Hdu_1002_let the Balloon Rise (analog)

Source: Internet
Author: User

Test instructions: Enter the color of n balloons (the color of the balloon is a string, up to 15 lowercase letters), output the color of the same color balloon, enter the 0 end program.

A balloon that guarantees that each group of data has a unique and up to one color.

Thinking: Using arrays of type string to save the color of n balloons

Examples:

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) Each element in the 2 is compared to each element in the cnt++, and the maximum number of elements is eventually saved in Word.

The subscript that records the maximum number of elements, stored in flag.

<span style= "FONT-SIZE:18PX;" > #include <iostream> #include <string>using namespace std;int main (int argc, char *argv[]) {int n;string An array of type color[1010];//string while (1) {string color[1010] = {""};//initialized to an empty array without this initialization will 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++;//element equals + +}}if (cnt > Word) {word = cnt;//The maximum number of elements saved in Word flag = i;//The index of the maximum number of elements}}cout << Color[flag] <&l T Endl }return 0;} </span>


Hdu_1002_let the Balloon Rise (analog)

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.