AcWing 490. 统计数字
原题链接
简单
作者:
偷月亮的喵
,
2024-12-23 08:51:25
,
所有人可见
,
阅读 1
/*#include <iostream>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
map<int,int> t;
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ){
int x;
cin >> x;
t[x]++;
}
for(auto [u,v] : t){
cout << u << ' ' << v << endl;//map 的key默认是升序的
}
return 0;
}*/
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int a[201000];
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i ++ ){
int j = i;
while(a[i] == a[j] && j <= n){
j++;
}
cout << a[i] << ' ' << j - i << endl;
i = j - 1;
}
return 0;
}