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     

 

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

转载于:https://www.cnblogs.com/cn19901203/archive/2012/08/17/2643646.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值