标签:
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=1004
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 80094 Accepted Submission(s): 30147
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 6 char color[1111][20],ch[20];//color[i][]表示第i个气球的颜色是XX颜色 7 int number[1111],n;//number[i]表示第i种颜色出现过几次 8 9 int main () 10 { 11 int i,j; 12 int ok, max, t, k; 13 while (scanf ("%d",&n)==1&&n) 14 { 15 memset(number, 0, sizeof(number)); 16 memset(color, ‘\0‘, sizeof(color));//初始化数组 17 k = 0; 18 for (i=0; i<n; i++) 19 { 20 scanf ("%s",ch); 21 ok = 0; 22 for (j=0; j<k; j++) 23 { 24 if (strcmp(ch, color[j])==0)//如果改颜色之前出现过,+1 25 { 26 number[j]++; 27 ok = 1; 28 } 29 } 30 if (!ok) 31 { 32 strcpy(color[k], ch);//如果改颜色没出现过,储存起来 33 number[k]++; 34 k++; 35 } 36 } 37 max = 0; 38 for (i=0; i<k; i++)//找到出现次数最多的颜色 39 { 40 if (number[i] > max) 41 { 42 max = number[i]; 43 t = i;//记录位置 44 } 45 } 46 printf ("%s\n",color[t]); 47 } 48 return 0; 49 }
标签:
原文地址:http://www.cnblogs.com/dxd-success/p/4235889.html