Hdu 1004 Let the Balloon Rise map解决方法

来源:互联网 发布:23种设计模式 java 编辑:程序博客网 时间:2024/06/04 23:54

原题地址http://acm.hdu.edu.cn/showproblem.php?pid=1004

#include<stdio.h>#include<map>#include<cstring>#include<string>using namespace std;map<string,int>m;int main(){    char s[1005][20];    int n;    while(~scanf("%d",&n)&&n!=0)    {        getchar();        m.clear();        int k = 0,max = 1;        char ss[20];        for(int i = 0;i<n;i++)        {            gets(s[i]);            if(m[s[i]] == 0)            {                m[s[i]] = 1;                k++;                //printf("%d\n",m[s[i]]);            }            else            {                m[s[i]]++;                if(m[s[i]] > max)                {                    max = m[s[i]];                    strcpy(ss,s[i]);                }            }        }        if(max != 1)            puts(ss);        else            for(int j=0;j<n;j++) puts(s[j]);    }    return 0;}


0 0
原创粉丝点击