#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define maxn 2000+10
#define N 75+10
char ss[N];
char country[maxn][maxn];
int cmp(const void *_a,const void *_b);
int main()
{
int n,i;
int len;
int total,q=0;
scanf("%d",&n);
getchar();
while(n--)
{
scanf("%s",ss);
while(getchar()!='\n');//只需记录国家名出现的次数
len=strlen(ss);
strcpy(country[q++],ss);
}
qsort(country,q,sizeof(country[0]),cmp);//国家名字典序
total=1;
for(i=1;i<=q;i++)
{
if(strcmp(country[i],country[i-1])==0)total++;//国家以字典序排列,只需比较相邻
else
{
printf("%s %d\n",country[i-1],total);
total=1;
}
}
return 0;
}
int cmp(const void *_a,const void *_b)
{
char* a=(char *)_a;
char* b=(char *)_b;
return strcmp(a,b);
}
UvaOJ 10420 战利品列表
最新推荐文章于 2020-03-30 09:46:34 发布