Hdu_1002_Let the Balloon Rise (simulation)

Source: Internet
Author: User

Hdu_1002_Let the Balloon Rise (simulation)

 

Enter the color of n balloons (the color of the balloon is a string with a maximum of 15 lowercase letters), and output the color of the balloon with the same color at most. Enter 0 to end the program.

Ensure that each group of data has a unique and most colored balloon.

Solution: Use a string array to save the colors of n balloons

Example:

1) a B a d e

2) a B a d e

A-> a B a d e

B-> a B a d e

C-> a B a d e

D-> a B a d e

1) compare each element in and 2). If they are equal, cnt ++ stores the maximum number of elements in word.

The subscript of the maximum number of elements in the record, which is stored in the flag.

 

# Include
 
  
# Include
  
   
Using namespace std; int main (int argc, char * argv []) {int n; string color [1010]; // string type array while (1) {string color [1010] ={}; // array whose Initialization is empty. if it is not initialized, WA cin >>> n; if (n = 0) return 0; for (int I = 0; I <n; I ++) {cin> color [I];} int cnt, flag = 10000; intword = 0; for (int I = 0; I <n; I ++) {cnt = 0; for (int j = 0; j <n; j ++) {if (color [I] = color [j]) {cnt ++; // if the element is equal, ++} if (cnt> word) {word = cnt; // The maximum number of elements is saved in word. flag = I; // The subscript that records the maximum number of elements }}cout <color [flag] <endl;} return 0 ;}
  
 


 

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.