- 绝对不难但又绝对坑人
- 用cin、cout 会超时
- 每个测试数据的输出之间还要空一行,最后一个测试数据不能有空行
- 用map 可以解决这个题目的排序问题, map内部使用的红黑树,会自动排序
//map 会自动排序
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int main()
{
bool flag = true;
int num;
while(cin >> num && num != 0)//题目也没说清楚到底是怎么结束
{
if(flag)
flag = false;
else
printf("\n");
map<int, int>counter;//关键字是数字, second是出现的次数
for(int i = 0; i < num; i++)
{
int temp;
/*cin >> temp;*/
scanf("%d", &temp);
map<int, int>::iterator itCounter = counter.find(temp);//是否已出现
if(itCounter == counter.end())//没出现过
{
counter[temp] = 1;//第一次
}
else//出现过
{
(*itCounter).second++;//次数+1
}
}
//输出
map<int, int>::iterator itCounter;
for(itCounter = counter.begin(); itCounter != counter.end(); itCounter++)
{
//cout << (*itCounter).first << " " << (*itCounter).second << endl;
printf("%d %d\n", (*itCounter).first, (*itCounter).second);
}
}
return 0;
}