1 #include <stdio.h> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 struct str 7 { 8 char s[30]; 9 int num; 10 }; 11 12 str a[1005]; 13 14 void init(int k) 15 { 16 for(int i=0;i<k;i++) 17 { 18 a[i].num=0; 19 } 20 } 21 22 23 int cmp(str a , str b) 24 { 25 return a.num>b.num; 26 } 27 28 int main() 29 { 30 int j; 31 int n; 32 char b[30]; 33 while(1) 34 { 35 36 scanf("%d",&n); 37 if(n==0)break; 38 init(n); 39 scanf("%s",a[0].s); 40 int count=0; 41 for(int i=1;i<n;i++) 42 { 43 scanf("%s",b); 44 for(j=0;j<=count;j++) 45 { 46 if(strcmp(b,a[j].s)==0) 47 { 48 a[j].num++; 49 break; 50 } 51 } 52 if(j-1==count) strcpy(a[++count].s,b); 53 } 54 sort(a,a+count+1,cmp); 55 printf("%s\n",a[0].s); 56 } 57 58 return 0; 59 }
对时间什么的要求的都不高,不涉及什么算法,只要不脑残,绝对快速AC