hdu 1004 Let the Balloon Rise

来源:互联网 发布:php 判断类是否存在 编辑:程序博客网 时间:2024/05/16 05:05

很久没做题了,闲来无事,找了道水题玩玩。

这题用Map做的话,很简单,若改用其他方法,可能有点小麻烦。

#include <iostream>#include <map>#include <cstring>using namespace std;int main(){//freopen("1.txt","r",stdin);//freopen("2.txt","w",stdout);int n;map<string,int>m;string str;while(scanf("%d",&n)==1 && n){m.clear();for(int i=0;i<n;i++){cin >> str;m[str]++;}map<string,int>::iterator p,q;int max=-1;for(p=m.begin(); p!=m.end(); p++)if(p->second > max){max=p->second;q=p;}cout << q->first << endl;}return 0;}


 

原创粉丝点击