HDU 1004 Let the Balloon Rise

来源:互联网 发布:redis mac 安装配置 编辑:程序博客网 时间:2024/06/06 07:02

查看原题

题意

输入颜色输出数量最多的颜色

思路

map

代码

#include <iostream>#include <map>#include <string>using namespace std;int main(int argc, char *argv[]){    int n;    string colors[1000];    map<string,int> m;    while(cin>>n){        int temp=0;        string t="";        m.clear();        if(n==0){            return 0;        }        else{            for(int i=0;i<n;i++){                cin>>colors[i];                m[colors[i]]++;                if(m[colors[i]]>temp){                    temp=m[colors[i]];                    t=colors[i];                }            }            cout<<t<<endl;        }     }    return 0;}
0 0