hdu 1004 Let the Balloon Rise

来源:互联网 发布:传销金字塔算法 编辑:程序博客网 时间:2024/05/22 17:07

Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 128387    Accepted Submission(s): 50713


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
5greenredblueredred3pinkorangepink0
 

Sample Output
redpink
 

Author
WU, Jiazhi
 

Source
ZJCPC2004
 

Recommend
JGShining   |   We have carefully selected several similar problems for you:  1008 1005 1009 1019 1021 




代码:
#include<iostream>#include<cstring>#include<algorithm>using namespace std;struct node{    char a[16];    int d;}s[1010];int cmp(node a,node b){    return a.d>b.d;}int main(){    int n;    while(cin>>n&&n)    {        for(int i=0;i<n;i++)        {            s[i].d=0;            cin>>s[i].a;            for(int j=0;j<i;j++)            {                if(strcmp(s[i].a,s[j].a)==0)                    s[i].d++;            }        }        sort(s,s+n,cmp);        cout<<s[0].a<<endl;    }    return 0;}


刚开始w,设了一个字符串a[],一个数组d[]存放个数,然后用sort,输出a[n-1]。要注意此时d没变,输出的还是原来的序列。