Let the Balloon Rise 1004
来源:互联网 发布:python 库安装 编辑:程序博客网 时间:2024/06/05 12:02
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57360 Accepted Submission(s): 20952
This year, they decide to leave this lovely job to you.
A test case with N = 0 terminates the input and this test case is not to be processed.
5greenredblueredred3pinkorangepink0
redpink
用容器map一下就解决了
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<map>
using namespace std;
const int MAXN=1000;
int main()
{
map<string,int>color;
string cnt;
string index;
int i;
int n;
int max;
while(scanf("%d",&n),n)
{
max=0;
while(n--)
{
cin>>cnt;
color[cnt]++;
if(color[cnt]>max)
{
index=cnt;
max=color[cnt];
}
}
cout<<index<<endl;
}
return 0;
}
不用容器的代码:
#include<iostream>
#include<cstring>
using namespace std;
struct node
{
char s[16];
int x;
}a1[1000],a2[1000];
int main()
{
int n,i,j;
while(~scanf("%d",&n))
{
if(n==0) break;
int k=0,m=0;
for(i=0;i<n;i++)
{
scanf("%s",a1[i].s);
a1[i].x=1;
strcpy(a2[i].s,a1[i].s);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(!strcmp(a1[i].s,a2[j].s))
a1[i].x++;
}
}
for(i=0;i<n;i++)
{
if(a1[i].x>m){
m=a1[i].x;
k=i;
}
}
printf("%s\n",a1[k].s);
}
return 0;
}
- 1004 Let the Balloon Rise
- 1004 Let the Balloon Rise
- 1004 Let the Balloon Rise
- 1004let the balloon rise
- Let the Balloon Rise 1004
- 1004 Let the Balloon Rise
- Let the Balloon Rise(1004)
- 1004Let the Balloon Rise
- Let the Balloon Rise(1004)
- Let the Balloon Rise(1004)
- 1004:Let the Balloon Rise
- 1004 let the balloon rise
- 1004 Let the Balloon Rise
- 1004 Let the Balloon Rise
- 1004-Let the Balloon Rise
- 1004 Let the Balloon Rise
- 1004 Let the Balloon Rise
- 1004 Let the Balloon Rise
- 学习GCD
- Jquery_Checkbox 完成全选,反选和全不选
- 世界上有三样东西不能相信(引用)心胸狭窄的男人勿看
- csapp2e 家庭作业 5.17
- Scanner类的学习
- Let the Balloon Rise 1004
- 提高代码性能及并发性的方法浅谈
- 数组指针与指针数组
- Perf -- Linux下的系统性能调优工具【转自IBM】
- 《黑客与画家》读后感
- hdu1180
- OpenFileDialog上传图片
- netty事件驱动总结
- empty()和isset()的区别