直接上代码:
一点感慨:不是什么问题都要直接上结构体,vector,pair,优先队列等类型,如果可以用更轻易地方式表示数据,那么就不要把问题复杂化,切记,切记。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int main() {
int n;
cin >> n;
int a[1005];
int b[1005];
for (int i = 0; i < n; i++) cin >> a[i];
memset(b, 0, sizeof(b));
for (int i = 0; i < n; i++) {
b[a[i]]++;
}
int large = 0, num = 0;
for (int j = 0; j < n; j++){
for (int i = 0; i < n; i++) {
if (b[a[i]] > large) {
large = b[a[i]]; num = a[i];
}
else if (b[a[i]] == large && a[i] < num) {
large = b[a[i]]; num = a[i];
}
}
if(large!=0) cout << num << " " << large << endl;
b[num] = 0; large = 0; num = 0;
}
return 0;
}
}