提交时间:2023-09-12 13:38:36

运行 ID: 102145

#include<bits/stdc++.h> #define int long long using namespace std; int n; struct node { int x; int pos; } node a[100001]; map<int,int> mp; bool cmp(node x,node y) { if(mp[x.x] == mp[y.x])return x.x<y.x; return mp[x.x] > mp[y.x]; } signed main() { cin >> n; for(int i = 1 ;i <= n ;i++) { cin >> a[i].x; mp[a[i].x]++; } sort(a+1 ,a+n+1 ,cmp); for(int i = 1;i <= n;i++) { if(i != 1 && a[i].x != a[i-1].x)cout << "->"; if(a[i].x != a[i-1].x)cout << a[i].x; } return 0; }