hdu 1800

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1800

题意:士兵要学骑扫帚。每个士兵有一个level,level高的能在同一把扫帚上教level低的怎么骑。一个人最多有一个老师,一个学生。也可以没有。给n个士兵的level值,问最少需要多少扫帚。

mark:显然就是找出现次数最多的数字的次数。但因为数字长度多达30个字符,因此long long都存不下,用字符串。

wa了一次,忘记处理前导0。

代码:

 1 # include <stdio.h>
 2 # include <string.h>
 3 # include <stdlib.h>
 4 
 5 
 6 char s[3010][35] ;
 7 
 8 
 9 int cmp(const void *a, const void *b)
10 {
11     return strcmp((char*)a, (char*)b) ;
12 }
13 
14 
15 int main ()
16 {
17     int n, i, j ;
18     int ans, cc ;
19     while (~scanf ("%d", &n))
20     {
21         for (i = 0 ; i < n ; i++)
22         {
23             scanf ("%s", s[i]) ;
24             for (j = 0 ; s[i][j] == '0' ; j++);
25             strcpy (s[i], s[i]+j) ;
26         }
27         qsort(s, n, sizeof(s[0]), cmp) ;
28         cc = 0 ;ans = 0 ;
29         for (i = 1 ; i < n ; i++)
30         {
31             if (strcmp(s[i], s[i-1])==0)
32                 cc++ ;
33             else 
34             {
35                 if (cc > ans) ans = cc ;
36                 cc = 0 ;
37             }
38         }
39         if (cc > ans ) ans = cc ;
40         printf ("%d\n",ans+1) ;
41     }
42     return 0 ;
43 }
原文地址:https://www.cnblogs.com/lzsz1212/p/2472911.html