HDOJ 1004 Let the Balloon Rise (map)
http://acm.hdu.edu.cn/showproblem.php?pid=1004
题意:求出现次数最多的颜色。
思路:用map存储颜色和出现次数,然后遍历一遍查找出现次数最多的即可。
#include<iostream>#include<string>#include<map>using namespace std;int main(){ int n; map <string,int> color; while(cin>>n&&n) { color.clear(); while(n--) { string ip; cin>>ip; if(color.find(ip)!=color.end()) color[ip]++; else color[ip]=1; } map<string,int>::iterator p; string op; int max=0; for(p=color.begin();p!=color.end();p++) { if(p->second>max) { op=p->first; max=p->second; } } cout<<op<<endl; } return 0;}