• 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
Copyright © 2020-2023  润新知