思路:这种串数字统计每个数字出现次数的题型都可以用map做,简单,CCF有好几道类似的题目,可以把它当做一个模板使用。
#include <iostream>
#include <map>
using namespace std;
int main(){
int n,v;
cin>>n;
map<int,int> m;
for(int i = 0; i < n; i++){
cin>>v;
m[v]++;
cout<<m[v]<<' ';
}
return 0;
}
使用Map统计数字频率
本文介绍了一种利用Map数据结构来统计一系列数字中各数字出现频率的方法。通过C++实现,适用于CCF等编程竞赛中类似题目的快速解决。代码简洁高效,可作为模板使用。
189

被折叠的 条评论
为什么被折叠?



