JosepRivaille

X01385: Diferents

May 10th, 2015
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int diferents(vector <int> &v) {
  6.   int cont=0;
  7.   int n = v.size();
  8.   for (int i=0; i<n; ++i) {
  9.     cin >> v[i];
  10.     int k=0;
  11.     bool trobat = false;
  12.     while (k<i and not trobat) {
  13.       if (v[k] == v[i]) {
  14.     trobat = true;
  15.       }
  16.       ++k;
  17.     }
  18.     if (not trobat) ++cont;
  19.   }
  20.   return cont;
  21. }
  22.  
  23. int main() {
  24.   int n;
  25.   while (cin >> n) {
  26.     vector <int> v(n);
  27.     int result = diferents(v);
  28.     cout << result << endl;
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment