C++ 统计自然数出现次数并排序输出
#include <iostream>
#include <map>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> countMap;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
countMap[num]++;
}
for (auto it = countMap.begin(); it != countMap.end(); it++) {
cout << it->first << ' ' << it->second << endl;
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/qnlg 著作权归作者所有。请勿转载和采集!