国内人做韩国网站一般都卖什么手续,php双语网站源码,西安wordpress主题,泰安可以做网站的公司链接和思路
OJ链接#xff1a;传送门
本题仅需用一个辅助数据结构Tmp记录每1个数字的值#xff08;value#xff09;及其出现的次数#xff08;cnt#xff09;#xff0c;然后重载运算符并针对cnt排序输出即可。辅助数据结构Tmp定义如下#xff1a;
struct Tmp {…链接和思路
OJ链接传送门
本题仅需用一个辅助数据结构Tmp记录每1个数字的值value及其出现的次数cnt然后重载运算符并针对cnt排序输出即可。辅助数据结构Tmp定义如下
struct Tmp {int value;int cnt;bool operator(const Tmp t) const {if (this-cnt ! t.cnt)return this-cnt t.cnt;return this-value t.value;}
} result[1005];其余见AC代码。
AC代码
#include bits/stdc.husing namespace std;int a[1005] {0};
int n;struct Tmp {int value;int cnt;bool operator(const Tmp t) const {if (this-cnt ! t.cnt)return this-cnt t.cnt;return this-value t.value;}
} result[1005];int main() {cin n;for (int i 0; i n; i) {int idx;cin idx;a[idx];}int curIdx 0;for (int i 0; i 1000; i) {if (a[i] ! 0) {result[curIdx].value i;result[curIdx].cnt a[i];curIdx;}}sort(result, result curIdx);for (int i curIdx - 1; i 0; --i) {cout result[i].value result[i].cnt endl;}return 0;
}