Hdoj (1004) Let the Balloon Rise

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.