首页 > 其他 > 详细

[HDU 1004]Let the Balloon Rise

时间:2014-10-21 00:40:20      阅读:283      评论:0      收藏:0      [点我收藏+]

字符串操作。


#include <cstdio>
#include <cstring>

using namespace std;
const int max = 1000 + 10;

int u,M,N;
int cnt[max];
char TTT[20] = "\n";
char str[max][20];
                
void OutAns()
{
    printf("%s\n",str[u]);
}
void back(int num)
{
    M = 0;
    for(int i = 0;i < num;i++)
        {
            cnt[i] = 0;
            strcpy(str[i],TTT);
        }
}

void init()
{
    char s[20];
    
    
    while(scanf("%d",&N) == 1 && N)
    {
        int num = 0,f = 0;
        for(int j = 1;j <= N;j++)
        {    
            f = 0;
            scanf("%s",s);
            for(int i = 0;i<=num;i++)
                if(!strcmp(s,str[i]))
                    {
                        f++;
                        cnt[i]++;
                        if(cnt[i] > M){u = i;M = cnt[i];}
                    }
            if(!f){strcpy(str[num],s);num++;}
        }
        OutAns();
        back(num);
    }
}

int main()
{
    init();
        
    return 0;
}

 

PS

    字符串操作的问题一直不好,然后代码一样难看,慢慢写吧。

[HDU 1004]Let the Balloon Rise

原文:http://www.cnblogs.com/5lyTher1n/p/4039191.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!