This question can be called "Let the Balloon Fly". Relatively simple, AC rate is relatively high, one-time pass.
The idea is to first create a string array color_table, with a different color to store, and an integral array count to store the number of occurrences of this index color in the corresponding color array. Whenever a program reads a color, it compares it with a color that already exists in the color array, adds 1 to the corresponding color if it already exists, and if the color is not found, it is a new color, and you need to add this color to the color_table. and add a total of 1 colors. The complete program code is as follows:
1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4 5 #defineMax_n 1000U/* Maximum number of colors to store */6 #definemax_l 15/* Maximum length of each color name */7 8 intMainvoid)9 {Ten CharColor_table[max_n][max_l];/*store different kinds of color names*/ OneUnsignedintCount[max_n], total;/*stores the number of occurrences and types of each color*/ A CharColor[max_l];/*the color used to cache the input*/ - intI, J, flag, Num;/*Store the number of colors that will be entered*/ - intPopular/*Store Most popular color indexes*/ the -scanf"%d", &num); - while(Num >0){ -Total =0; +memset (Count,0,sizeof(count)); - + for(i =0; i < num; i++){ Ascanf"%s", color);/*read in a color*/ at - /*Check if the color already exists*/ -Flag =0; - for(j =0; J < Total; J + +){ - if(strcmp (color, color_table[j]) = =0){ -count[j]++; inFlag =1;//indicates that the color is found - Break; to } + } - /*The color does not exist and is added to the color table*/ the if(Flag = =0) { * strcpy (color_table[total], color); $count[total]++;Panax Notoginsengtotal++; - } the } + A /*find the most popular colors*/ thePopular =0; + for(i =1; I < total; i++){ - if(Count[popular] <Count[i]) { $Popular =i; $ } - } -printf"%s\n", Color_table[popular]); the -scanf"%d", &num);Wuyi } the - return 0; Wu}
Hdoj (1004) Let the Balloon Rise