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.
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.
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==0) break;
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;
}
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==0) break;
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
- HDOJ1004
- hdoj1004
- hdoj1004
- hdoj1004
- HDOJ1004
- hdoj1004
- hdoj1004
- HDOJ1004
- HDOJ1004
- HDOJ1004
- HDOJ1004字符串
- hdoj1004-java
- hdoj1004(寻找最长平台)
- hdoj1004简单题
- HDOJ1004 so easy
- hdoj1004解题报告
- HDOJ1004(让气球升起)
- HDOJ1004:Let the Balloon Rise
- HDOJ1003 Max Sum
- vs2005中的树形菜单(方法成品属于javascrip版)
- 微软的面试题及答案(超变态但很经典)
- 谨慎!使用AJAX技术的七个易忽视的错误
- .NET环境下几种不同的邮件发送解决方案
- HDOJ1004
- 深度探索C++对象模型
- C++中基本的文件操作
- HDOJ1005 Number Sequence
- 雅虎公司C#笔试题
- 表连接查询分类
- 常见ASP.NET高试出错信息及解决办法
- 博客代码大全的主页,厉害厉害
- DB2 日期数据的处理