Hdu-1004-let the Balloon Rise (direct new A string array compareto!)

Source: Internet
Author: User

Let the Balloon RiseTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 85666 Accepted Submission (s): 32330


Problem Descriptioncontest Time again! How excited it was to see balloons floating around. But to tell you a secret, the judges ' favorite time was guessing the most popular problem. When the contest was over, they would count the balloons of each color and find the result.

This is the year that they decide to leave the lovely job to you.

Inputinput contains multiple test cases. Each test case is starts with a number n (0 < N <=) – The total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to lower-case letters.

A test Case with N = 0 terminates the-input and this-test case are not-to-be processed.

Outputfor each case, print the color of balloon for the most popular problem to a single line. It is guaranteed this there is a unique solution for each test case.

Sample Input
5greenredblueredred3pinkorangepink0

Sample Output
Redpink

AUTHORWU, Jiazhi
SourceZJCPC2004
recommendjgshining | We have carefully selected several similar problems for you:1008 1005 1003 1009 1019

Explain the topic: the main meaning of the topic is multiple case input: Each case the first line is n, contains n data, that is, the color of n strings read into, calculate the most occurrences of the color and output!
The topic is very simple! I've built a string array here in Java string[] Strarray = new String[n]; To save each color, Use an integer a array to hold the number of occurrences of each color. (The subscript of the array of arrays corresponds to the subscript of the string array Strarray) finally calculates the maximum number of occurrences, the output is OK! This is straight straight to the question No turning! Easy accpted Everyone oier 51 Happy Holidays!

Import Java.io.*;import java.util.*;p ublic class main{public static void Main (string[] args) {//TODO auto-generated Metho D stubscanner input = new Scanner (system.in), while (Input.hasnext ()) {int n = input.nextint (); if (n = = 0) Break;input.nextli NE (); string[] Strarray = new String[n];int a[] = new Int[n];for (int i = 0; i < n; i++) {Strarray[i] = Input.nextline ();} for (int i = 0, i < n; i++) {for (int j = 0; J < N; j + +) {if (Strarray[i].compareto (strarray[j]) = = 0) {a[i]++;}}} int flag = 0;int max = 0;for (int i = 0; i < n; i++) {if (A[i] > max) {max = A[i];flag = i;}} System.out.println (Strarray[flag]);}}


Hdu-1004-let the Balloon Rise (directly new a string array compareto!)

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.