#include #include #include #include using namespace std; //Time Limit: 1.0s, Memory Limit: 256.0M struct Elem { int key; int value; bool operator < (const Elem &elem) { if (elem.value == value) { return elem.key > key; } else return elem.value < value; } }; void main() { int n; int input; vector outcome; map record; map::iterator it; cout << "请输入整数个数:"; cin >> n; //存入map cout << "请输入整数:" << endl; for (int i = 0; i < n; i++) { cin >> input; record[input]++; } //存入vector for (it = record.begin(); it != record.end(); it++) { Elem elem; elem.key = it->first; elem.value = it->second; outcome.push_back(elem); } sort(outcome.begin(),outcome.end()); for (int i = 0; i < outcome.size(); i++) { cout << outcome[i].key << " " << outcome[i].value << endl; } }
上一篇 课程设计--基于模板的顺序表的使用
下一篇 CCF-CSP试题201912-2回收站选址 暴力解法
版权所有 (c)2021-2022 MSHXW.COM
ICP备案号:晋ICP备2021003244-6号