Advertisement
aimon1337

de cate ori apare un nr in array

Jan 29th, 2020
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int v[250];
  4. int n,x;
  5. int nr=0;
  6. int deti(int li, int ls)
  7. {
  8.     if(li==ls)
  9.     {
  10.         if(v[li]==x)
  11.             {nr++;
  12.             return nr;}
  13.     }
  14.     else
  15.     {
  16.         int mij,s1,s2;
  17.         mij=(li+ls)/2;
  18.         s1=deti(li,mij);
  19.         s2=deti(mij+1,ls);
  20.         if(s1 || s2)
  21.             return nr;
  22. //        else
  23. //            exit(-1);
  24.     }
  25.  
  26. }
  27.  
  28. int main()
  29. {
  30.     int i,n;
  31.     cin>>n;
  32.     for(i=1;i<=n;++i)
  33.         cin>>v[i];
  34. //    int x;
  35.     cin>>x;
  36.     cout<<deti(1,n);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement