zoj 2014 Let the Balloon Rise(水~)

找出出现颜色次数最多的颜色~

 

我用结构体了,数组开得有点小,WA了一次。。悲剧。。。

 

因为WA搜别人代码时,搜到某柯的了,用的map??map是啥。。图么。。不会哎。。

 

他大一的现在都已经好强了。。。哎。。好惭愧呀。。

 

#include <stdio.h> #include <stdlib.h> #include <string.h> struct ballon { char color[20]; int count; }ball[1002]; int main(void) { int n,num,i,max,y,j,tempi; char col[10]; while( scanf("%d",&n) && n) { for(i=0; i<20; i++) ball[i].count = 0; num = 1; y = 1;max = 0; scanf("%s",ball[0].color); ball[0].count = 1; for(j=1; j<n; j++) { y = 1; scanf("%s",col); for(i=0; i<num; i++) { if( strcmp(col,ball[i].color) == 0) { y = 0; ball[i].count++; } } if( y ) { strcpy(ball[num].color,col); ball[num].count = 1; num++; } } for(i=0; i<n; i++) { if(ball[i].count > max) { tempi = i; max = ball[i].count; } } printf("%s/n",ball[tempi].color); } system("pause"); return 0; }

你可能感兴趣的:(System)