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;
    
    }
  • 相关阅读:
    win10下jdk8和jdk11切换的批处理脚本
    Deeping中使用python连接Oralce报错:Cannot locate a 64-bit Oracle Client library: "./instantclient_21_1/libclntsh.so: file too short"
    Redis作者“不懂”分布式锁【转载】
    搭建nacos高可用集群
    使用spring.config.location与本地配置文件属性不能互补
    protocol buffer应用场景方案想法
    protocol buffer 入门和基本知识
    IDEA快捷键
    软考问题总结
    pandas 使用问题记录
  • 原文地址:https://www.cnblogs.com/wos1239/p/4387398.html
Copyright © 2011-2022 走看看