zoukankan      html  css  js  c++  java
  • hdu1004Let the Balloon Rise

    Problem Description
    Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
    This year, they decide to leave this lovely job to you.
     
    Input
    Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
    A test case with N = 0 terminates the input and this test case is not to be processed.
     
    Output
    For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
     
    Sample Input
    5 green red blue red red 3 pink orange pink 0
     
    Sample Output
    red pink
     
    Author
    WU, Jiazhi
     
    Source
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    
    using namespace std;
    
    struct node
    {
        node* next[26];
        bool end;
        int num;
        node()
        {
            for(int i = 0;i<26;i++)
                next[i] = NULL;
            end = 0;
            num = 0;
        }
    };
    node* root;
    char s[100],ma[100];
    int mx;
    int insert()
    {
        int l =strlen(s);
        node* k = root;
        int i,j;
        for(i = 0;i<l-1;i++)
        {
            int id = s[i]-'a';
            if(k->next[id] == NULL)
            {
                node* t = new node();
                k->next[id] = t;
                k = k->next[id];
            }
            else
            {
                k = k->next[id];
            }
        }
        int id = s[i]-'a';
        if(k->next[id] == NULL)
        {
            node* t = new node();
            t->end = 1,t->num = 1;
            k->next[id] = t;
            k = k->next[id];
        }
        else
        {
            k = k->next[id];
            k->num++;
        }
        return k->num;
    }
    
    int main()
    {
        int n,i,j,k;
        while(cin>>n,n)
        {
            root = new node();
            mx = 0;
            for(i = 0;i<n;i++)
            {
                cin>>s;
                int t = insert();
                if(mx<t)
                {
                    mx = t;
                    int l = strlen(s);
                    for(j = 0;j<=l;j++)
                        ma[j] = s[j];
                }
            }
            cout<<ma<<endl;
        }
        return 0;
    
    }
  • 相关阅读:
    Vue 踩坑-2 vue文件中style的scoped属性
    IIS发布Vue项目F5刷新404问题
    .NET Core 3.1 + Hangfire 配置以及踩坑
    Vue 踩坑-1-跨域问题
    Docker 部署VUE项目
    (转)如何利用EnteLib Unity Interception Extension 和PIAB实现Transaction的Call Handler
    Unity 中的策略注入(转)
    面向方面的编程、侦听和 Unity 2.0(转)
    Unity 中的拦截功能(转)
    [转]推荐分享22个优秀的项目管理与协作工具
  • 原文地址:https://www.cnblogs.com/wos1239/p/4387398.html
Copyright © 2011-2022 走看看