Advertisement
apl-mhd

distinctCodility

Aug 19th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include<cstdio>
  2. #include<vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int solution(vector<int> &A){
  8.  
  9.     int i, count = 0, N;
  10.     std::sort(A.begin(), A.end());
  11.  
  12.    // N = A.size();
  13.  
  14.     for( i = 0; i < A.size()-1; i++ ){
  15.  
  16.  
  17.         if(A[i] - A[i + 1] != 0 ){
  18.  
  19.             count++;
  20.         }
  21.  
  22.  
  23.     }
  24.  
  25.    return count;
  26.  
  27. }
  28.  
  29.  
  30.  
  31. int main(){
  32.  
  33.     vector <int> number{2,1,1,2,3,5};
  34.     vector <int> number2{0};
  35.     vector <int> number3{1, 1, 14, 1000, 1};
  36.  
  37.  
  38.     printf(" %d \n", solution(number) == 3);
  39.     printf(" %d \n", solution(number2) == 1);
  40.     printf(" %d \n", solution(number3) == 3);
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.     return 0;
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement