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;
}