Advertisement
FreakSkipper

Treinamento

Aug 29th, 2020
1,578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. // Treinamento
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. void ordena_vetor(vector<int>& v) {
  7.     for (int i = 0; i < (int)v.size() - 1; i++) {
  8.         for (int j = i + 1; j < (int)v.size(); j++) {
  9.             if (v[i] > v[j]) {
  10.                 int aux = v[i];
  11.                 v[i] = v[j];
  12.                 v[j] = aux;
  13.             }
  14.         }
  15.     }
  16. }
  17.  
  18. int main() {
  19.     int n;
  20.    
  21.     cin >> n;
  22.  
  23.     vector<int> a(n);
  24.  
  25.     for (int i = 0; i < n; i++) {
  26.         cin >> a[i];
  27.     }
  28.    
  29.     ordena_vetor(a);
  30.    
  31.     // cout << "vetor: ";
  32.     // for (auto& e:a) {
  33.     //     cout << e << ' ';
  34.     // }
  35.     // cout << '\n';
  36.  
  37.     int aux = a.front();
  38.     int contador = 1;
  39.  
  40.     for (int i = 1; i < n; i++) {
  41.         if (aux != a[i]) {
  42.             aux = a[i];
  43.             contador++;
  44.         }
  45.     }
  46.  
  47.     cout << contador << endl;
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement