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;
    
    }
  • 相关阅读:
    使用BigQuery分析GitHub上的C#代码
    ASP.NET Core 处理 404 Not Found
    C# 7 局部函数剖析
    调试 ASP.NET Core 2.0 源代码
    Entity Framework Core Like 查询揭秘
    ASP.NET Core Razor 视图组件
    Thread 1 cannot allocate new log引起的宕机事故(转载)
    docker默认网段和主机网段冲突解决
    docker安装异常以及网络问题总结
    max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
  • 原文地址:https://www.cnblogs.com/wos1239/p/4387398.html
Copyright © 2011-2022 走看看