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;
    
    }
  • 相关阅读:
    通过docker构建zabbix监控系统
    python中执行shell命令
    silverlight计时器的使用
    Silverlight学习笔记2:Silverlight中使用多线程实现倒计时
    silverlight全屏模式
    ASP.NET后台调用JavaScript
    JavaScript容易误解的概念
    Silverlight学习笔记1:创建一个Silverlight应用程序
    JavaScript中==和===的区别
    利用Visual Studio International Pack 实现对汉字的简单操作
  • 原文地址:https://www.cnblogs.com/wos1239/p/4387398.html
Copyright © 2011-2022 走看看