P1097 题解
题目传送门
思路
本题考察 map 的基本语法。
首先考虑桶,对于每一个数,对应的桶增加
于是考虑 map。读入照常,对于读入的数 it 遍历一遍 map,分别输出 map 中存储的对应数字及其数量,分别为 it->first 和 it->second。
map 的一次修改是
AC CODE
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,x;
map<int,int>mp;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&x),++mp[x];
for(auto it=mp.begin();it!=mp.end();++it)
printf("%d %d\n",it->first,it->second);
return 0;
}