Advertisement
informaticage

redundant

Dec 10th, 2023
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int conta_occ(int V[], int len, int x, int i = 0) {
  5.   if (len == i) return 0;
  6.   if (V[i] == x) return 1 + conta_occ(V, len, x, i + 1);
  7.  
  8.   return conta_occ(V, len, x, i + 1);
  9. }
  10.  
  11. bool is_redundant(int V[], int len, int i = 0) {
  12.   if (len == i) return true;
  13.   if (conta_occ(V, len, V[i]) != 2) {
  14.     return false;
  15.   }
  16.  
  17.   return is_redundant(V, len, i + 1);
  18. }
  19.  
  20.  
  21. int main() {
  22.   int arr[] = {1, 1, 4, 4, 5, 3, 3, 5 };
  23.  
  24.   cout << is_redundant(arr, sizeof(arr) / sizeof(arr[0]));
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement