fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define name "LIETKE"
  5. const int MAXN = 2e5+5;
  6. int n, a[MAXN];
  7.  
  8. void setIO(){
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0); cout.tie(0);
  11. if (fopen(name".inp", "r")){
  12. freopen(name".inp", "r", stdin);
  13. freopen(name".out", "w", stdout);
  14. }
  15. }
  16.  
  17. void inp(){
  18. cin >> n;
  19. for (int i = 1; i<=n; i++) cin >> a[i];
  20. }
  21.  
  22. int main(){
  23. setIO(); // Nhập xuất file
  24. inp();
  25. int i = 1, dem = 1;
  26. sort(a + 1, a+n+1);
  27. while (i<n){
  28. if (a[i] == a[i+1])
  29. dem++;
  30. else{
  31. cout << a[i] << " " << dem <<"\n";
  32. dem = 1;
  33. }
  34. i++;
  35. if (i==n) cout << a[i] << " " << dem <<"\n";
  36. //Câu lệnh để in ra số cuối cùng
  37. }
  38. }
Success #stdin #stdout 0.01s 5320KB
stdin
8
1 -1 2 1 3 4 200 5 
stdout
-1 1
1 2
2 1
3 1
4 1
5 1
200 1