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;
    
    }
  • 相关阅读:
    家庭记事本开发进度1
    仓库信息管理系统
    文件与流动手动脑和课后作业
    课堂测试
    Java异常处理
    动手动脑五
    动手动脑4
    记录类的个数
    数据结构
    操作系统
  • 原文地址:https://www.cnblogs.com/wos1239/p/4387398.html
Copyright © 2011-2022 走看看