hdoj 1004 Let the Balloon Rise(map)

来源:互联网 发布:java hello world 代码 编辑:程序博客网 时间:2024/05/20 06:55

Let the Balloon Rise(链接)



Sample Input
5greenredblueredred3pinkorangepink0
 

Sample Output
redpink
 
输出出现次数最多的颜色  用map存一下就好了
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>using namespace std;int main(){    map<string,int> B;    string Color,Max;    int n;    while(~scanf("%d",&n)&&n!=0)    {        B.clear();        while(n--)        {            cin>>Color;            B[Color]++;        }        int max=0;        map<string,int>::iterator it;   //迭代器        for(it=B.begin();it!=B.end();it++)        {            if(it->second>max)            {                max=it->second;    //只能用  ->  不可以用dian点.                Max=it->first;            }        }        cout<<Max<<endl;    }    return 0;}