提交时间:2024-01-25 09:05:39
运行 ID: 127434
#include <iostream> #include <algorithm> using namespace std; struct cave { int pcnt, id; }cnt[100100]; int a[20000]; bool cmp(cave x, cave y) { if(x.pcnt != y.pcnt) return x.pcnt > y.pcnt; return x.id < y.id; } int main() { int n; cin >> n; for(int i = 1; i <= n; i++) {cin >> a[i]; cnt[a[i]].pcnt++; cnt[a[i]].id = a[i];} sort(cnt + 1, cnt + n + 1, cmp); cout << cnt[1].id; for(int i = 2; i <= 1500; i++) if(cnt[i].pcnt) cout << "->" << cnt[i].id; cout << endl; return 0; }