JosepRivaille

P25401: Quants de diferents?

Jun 2nd, 2015
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6.  
  7. void read_vector(vector<int>& v) {
  8.     int tam = v.size();
  9.     for (int i = 0; i < tam; ++i) {
  10.         cin >> v[i];
  11.     }
  12. }
  13.  
  14.  
  15. int main() {
  16.     int n;
  17.     while (cin >> n) {
  18.         vector<int> v(n);
  19.         read_vector(v);
  20.         sort(v.begin(), v.end());
  21.         int comp = v[0];
  22.         int count = 1;
  23.         for (int i = 0; i < n; ++i) {
  24.             if (v[i] != comp) {
  25.                 ++count;
  26.                 comp = v[i];
  27.             }
  28.         }
  29.         cout << count << endl;
  30.     }
  31. }
  32.  
  33. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment