提交时间:2024-01-25 09:51:39
运行 ID: 127675
#include <bits/stdc++.h> using namespace std; struct cave{int pcnt, id;}cnt[100100]; int a[2001000]; bool cmp(cave x, cave y){ if(x.pcnt != y.pcnt) return x.pcnt > y.pcnt; else return x.id < y.id; } int main() { int h, maxn = -1; cin >> h; for(int i = 1; i <= h; i++){ cin >> a[i]; maxn = max(maxn, a[i]); cnt[a[i]].pcnt++; cnt[a[i]].id = a[i]; } sort(cnt + 1, cnt + maxn + 1, cmp); cout << cnt[1].id; for(int i = 2; i <= 400; i++){ if(cnt[i].pcnt) cout << "->" << cnt[i].id; } cout<<endl; }