acm-water problem let the balloon rise--hdu1004

Source: Internet
Author: User

Let the Balloon Rise Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 65180 Accepted Submission (s): 24152


Problem Description Contest 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.

Input input 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.

Output for each case, print the color of balloon for the most popular problem on a. It is guaranteed this there is a unique solution for each test case.

Sample Input

5 green red Blue Red Red 3 pink Orange Pink 0
Sample Output
Red Pink


Well, long time no problem,

From yesterday noon to today has been tangled with a water problem,

I thought for a while that my vacation had been a muddle (3 days off),

Oh, I didn't think so.

Always put

Runtime Error
(access_violation)

As

Time Limit exceeded

Forcing me to streamline my time and again,

Finally, with the help of Baidu to see a child change the array size from 1000 to 1001 on AC

I tried it too, sure enough.

#include <iostream>
#include <string>
#include <cstring>

using namespace std;
int main () {
	string str;
	String bln[1001];
	int blon[1001]={0};
	int i,j,k,max,ma,l,n;

	while (cin>>n&&n!=0)
	{
		j=0;		Equivalent to having several color balloons for
		(i=0;i<n;++i)
		{
			cin>>str;
			if (0==i)
			{
				bln[0]=str;
				++j;
				ma=0;		Ma records the position of the maximum number of balloons
				max=0;
				Continue;
			}
			for (k=0;k<j;++k)
			{
				l=0;			L Determine if the balloon color number should be added 1
				if (Str==bln[k])
				{
					++blon[k];
					if (Blon[k]>max)
					{
						max=blon[k];
						ma=k;
					}
					l=1;
					break;
				}
			}
			if (0==l)
			{
				bln[j]=str;
				++j;
				Continue;
			}
		}
		cout<<bln[ma]<<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.