uva 10420 List of Conquests

很简单的题目不用管后面的女性的名字,只需要吧出现的国家的次数记录下来,然后按国家的顺序输出就行了

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 struct node
 5 {
 6     char coun[80];
 7     int num;
 8 };
 9 int cmp ( const void *a , const void *b )
10 {
11 return strcmp( (*(struct node *)a).coun , (*(struct node *)b).coun );
12 }
13 int main()
14 {
15     struct node name[2102];
16     char st[80];
17     int T, i, j,top = 0;
18     scanf("%d",&T);
19     getchar();
20     for(i = 0;i < T; i++)
21     {
22         scanf("%s",st);
23         for(j = 0;j < top; j++)
24         {
25             if(strcmp(st,name[j].coun) == 0)
26             {
27                 name[j].num++;
28                 break;
29             }
30         }
31         if(j == top)
32         {
33             name[top].num = 1;
34             strcpy(name[top++].coun,st);
35         }
36         gets(st);
37     }
38     qsort(name,top,sizeof(name[0]),cmp);
39     for(i = 0;i < top; i++)
40     printf("%s %d\n",name[i].coun,name[i].num);
41     return 0;
42 }
原文地址:https://www.cnblogs.com/SDUTYST/p/2533046.html