自從 暑假 ACM集訓之後就再也沒有碰過 ACM了 以前說出去的話都是潑出去的水啊 哈哈哈
水一道題啊 一年過去了
Problem Description Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
Input Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
Output For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
Sample Input 5 green red blue red red 3 pink orange pink 0
Sample Output red pink 思路就是:一個字符型二維數組用來存顏色,一個一維整數型數組用了存顏色出現的次數。之後再拿第一個顏色掃一遍,遇見相同的count++,再拿第二個顏色掃一遍,這個用兩個for語句。 菜的摳腳啊 水不出來還是抄到其他人的思路的......
1 #include <stdio.h> 2 #include <string.h> 3 int main() 4 { 5 int n,max,i,j; 6 char a[1000][15],b[1000]; 7 while(scanf("%d",&n)&&n) 8 { 9 for(i=0; i<n; i++) 10 { 11 scanf("%s",&a[i]); 12 b[i]=0; 13 } 14 for(i=0; i<n; i++) 15 { 16 for(j=i+1;j<n;j++) 17 if(strcmp(a[i],a[j])==0) 18 b[i]++; 19 } 20 max=0; 21 for(i=0;i<n;i++) 22 if(max<b[i]) 23 max=i; 24 printf("%s\n",a[max]); 25 } 26 return 0; 27 }