题目描述
输入学生的总分,统计各个分数的人数。
输入
第1行是学生人数n。
第2行--第n+1行为输入每个学生的分数。
输出
按照分数从小到大的顺序输出各个分数以及该分数的人数。
样例输入
10 80.5 70 80.5 70.5 73.3 70.5 80.5 70 90 90
样例输出
70 2 70.5 2 73.3 1 80.5 3 90 2
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{ int n;
string s;
map<string,int> mp;
map<string,int>::iterator it;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s;
it=mp.find(s);
if(it==mp.end())
mp.insert(pair<string,int>(s,1));
else it->second++;
}
for(it=mp.begin();it!=mp.end();it++)
cout<<it->first<<" "<<(*it).second<<endl;
}