HDOJ1004

来源:互联网 发布:网络上买的微信号提现 编辑:程序博客网 时间:2024/05/18 02:17
 

Let the Balloon Rise

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


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
 

Source
WU, Jiazhi
 

Recommend
JGShining
 
/*
  Name: 1004 
  Copyright: 
  Author: 
  Date: 26-07-07 15:00
  Description: 注意一下 #include <string>  第一次提交时,Compilation Error 
*/


#include 
<iostream>
#include 
<string>
using namespace std;
int main()
{
    
int T;
   
    
while(cin>>T)
    
{
                 
if(T==0break;
                 
string *b=new string[T];//ball的原始数组 
                 string *a=new string[T];//种类,ball的种类 
                 int *c=new int[T];//记录count的数量 
                 int point=0;//记录count的指针 
                 for(int i=0;i<T;i++)
                 c[i]
=0;
                 
for(int i=0;i<T;i++)
                 
{
                         cin
>>b[i];
                         
//比较重复的,进行统计 
                         int flag=0;
                          
int j=0;
                          
for(;j<point;j++)
                          
if(b[i]==a[j])
                          
{
                                        c[j]
++;
                                        flag
=1;
                                        
break;
                          }

                          
if(flag==0)
                          
{
                                     a[j]
=b[i];
                                     c[j]
++;
                                     point
++;
                          }

                          
                          
                                         
                          
                 }

                 
int max=0;
                 
int index=-1;
                 
for(int i=0;i<point;i++)
                 
if(max<c[i])
                 
{
                             max
=c[i];
                             index
=i;
                 }

                 
                 
                 cout
<<a[index]<<endl;
                 delete [] b;
                 delete [] a;
                 delete [] c;
                 
                         
                 
                 
                 
                 
    }

      
      
     
// system("pause");
return 0;
}
 
Download the code
http://dl2.csdn.net/down4/20070726/26160202304.cpp
原创粉丝点击