HDU 1004 Let the Balloon Rise (map use)

Source: Internet
Author: User

Analysis: Test instructions simple, with the knowledge of map can be

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <map>
using namespace std;


int main ()          
{
	int i,a,b,k;
	int N;
	Char num[10];
    while (~SCANF ("%d", &n))
    {
		map<string,int> MP;
	    while (n--)
	    {
			scanf ("%s", num);
			mp[num]++;			
	    }
		Map<string,int>::iterator iter;
		int max=-1;
		For (Iter=mp.begin (); ITER! = Mp.end (); iter++)
		{
			if (Iter->second > Max)
			{
				max=iter-> second;
			}
		}
		For (Iter=mp.begin (); ITER! = Mp.end (); iter++)
		{
			if (Max==iter->second)
			{
				cout<<iter- >first<<endl;
				Break
    ;
	
	}}} return 0;
}

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


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
Author WU, Jiazhi
Source ZJCPC2004

2015-10-17


#include <iostream>
#include <string>
#include <map>
using namespace std;

int main ()
{
	int t;
	int num;
	int Max;
    string S;
	string Smax;

	while (cin>>t,t)
	{
		 max = 0;			 
		 Map<string, int> m;

		 while (t--)
		 {			 
			 cin>>s;
			 m[s]++;
			 if (M[s] > Max)
			 {
				 max = m[s];
			     Smax = s;
			 }
		 }
		 cout<<smax<<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.