Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 79774 Accepted Submission(s): 29991
This year, they decide to leave this lovely job to you.
A test case with N = 0 terminates the input and this test case is not to be processed.
5 green red blue red red 3 pink orange pink 0
red pink
如果数组下表能用字符串表示就好了,有机会自己创......嘿嘿
所以就要用到结构体,需要字符串比较,字符串赋值的知识点。
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; char s1[20]; struct point { char s[20]; int count; }color[1005]; int main(void) { // freopen("C.txt","r",stdin); int n; while(scanf("%d",&n)!=EOF&&n) { for(int i=1;i<=1000;i++) color[i].count=0; int k=0; while(n--) { scanf("%s",s1); int ok=0; for(int i=1;i<=k;i++) { if(strcmp(color[i].s,s1)==0) { color[i].count++; ok=1; break; } } if(ok==0) { strcpy(color[++k].s,s1); color[k].count=1; } } for(int i=2;i<=k;i++) { if(color[i].count>color[1].count) { color[1].count=color[i].count; strcpy(color[1].s,color[i].s); } } cout<<color[1].s<<endl; } return 0; }