首页 > 代码库 > [HDU 1004]Let the Balloon Rise

[HDU 1004]Let the Balloon Rise

字符串操作。


#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