题解:P1097 [NOIP2007 提高组] 统计数字
wanghonghui123 · · 题解
思路
这题就是先把序列用 set 去重,然后题目要让我们统计每个数出现的次数,可以用桶做,可以用下标数组,要可以用 STL 里的 map。要注意输出时的下标。
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
set<int> st;
map<int,int> mp;
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
int t;
cin>>t;
st.insert(t);
mp[t]++;
}
for(auto it:st){
cout<<it<<' '<<mp[it]<<endl;
}
return 0;
}