HDU 1014 字符串处理

View Code
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h>
 4 #define N 1005
 5 
 6 typedef struct
 7 {
 8    char s[15];
 9    int count;
10 }Color;
11 Color C[N];
12   
13 int cmp(const void *a,const void *b)
14 {
15     if( (*(Color *)a).count > (*(Color *)b).count)
16        return 1;
17     return -1;
18 }
19             
20 int main()
21 {
22     int i,j,ncases;
23     
24     while(scanf("%d",&ncases) && ncases)
25     {
26        for(i=0; i<ncases; i++) 
27        { 
28            scanf("%s",C[i].s);    
29            C[i].count = 1;
30            for(j = 0; j < i; j++)
31            {
32              if(strcmp(C[j].s,C[i].s)==0)    
33                  C[j].count++;
34            }      
35         } 
36         qsort(C,ncases,sizeof(Color),cmp);  
37         
38        printf("%s\n",C[ncases-1].s);  
39     }
40     return 0;
41 }
42     

 

我把今天上午做的几道水题贴上吧。

posted @ 2012-08-17 10:48  zhongya  阅读(171)  评论(0编辑  收藏  举报