Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

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
题意:找出出现次数最多的那个字符串;
strcmp:
#include<stdio.h>
#include<string.h>
char a[][];
int b[];
int main ()
{
int x,y,z,j,k,i,t,max;
while(scanf("%d",&x)!=EOF)
{
if(x==)
break;
getchar();
memset(b,,sizeof(b));
for(i=;i<x;i++)
scanf("%s",a[i]);
for(i=;i<x;i++)
for(t=;t<x;t++)
if(strcmp(a[i],a[t])==)
b[i]++;
max=b[];
k=;
for(i=;i<x;i++)
if(max<b[i])
{max=b[i];k=i;}
printf("%s\n",a[k]);
}
return ;
}

map:

#include<stdio.h>
#include<map>
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
int main()
{
int x,y,z,i,t,max;
string a,b;
map<string,int>p;
while(scanf("%d",&x)!=EOF)
{
getchar();
p.clear();
if(x==) break;
max=;
for(i=;i<x;i++)
{
cin>>a;
p[a]++;
if(p[a]>max)
{
max=p[a];
b=a;}
}
cout<<b<<endl;
}
return ;
}

trie树:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e5+,M=5e6+,inf=1e9+;
int a[N][],sum[M],len,ans=;
void init()
{
memset(a,,sizeof(a));
memset(sum,,sizeof(sum));
len=;
ans=;
}
char aaa[N];
int getnum(char a)
{
return a-'a';
}
void insertt(char *aa)
{
int u=,n=strlen(aa);
for(int i=; i<n; i++)
{
int num=getnum(aa[i]);
if(!a[u][num])
{
a[u][num]=len++;
}
u=a[u][num];
sum[u]++;
}
if(sum[u]>ans)
{
ans=sum[u];
strcpy(aaa,aa);
}
}
int getans(char *aa)
{
int u=,x=strlen(aa);
for(int i=; i<x; i++)
{
int num=getnum(aa[i]);
if(!a[u][num])
return ;
u=a[u][num];
}
return sum[u];
}
char ch[N];
int main()
{
int x,y,z,i,t;
while(~scanf("%d",&x))
{
if(x==)break;
init();
for(i=; i<x; i++)
{
scanf("%s",ch);
insertt(ch);
}
printf("%s\n",aaa);
}
return ;
}
 

hdu 1004 Let the Balloon Rise strcmp、map、trie树的更多相关文章

  1. HDU 1004 Let the Balloon Rise(map的使用)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

  2. HDU 1004 - Let the Balloon Rise(map 用法样例)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  3. hdu 1004 Let the Balloon Rise(字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

  4. HDU 1004 Let the Balloon Rise【STL<map>】

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  5. HDU 1004 Let the Balloon Rise map

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  6. hdu 1004 Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. HDU 1004 Let the Balloon Rise(map应用)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  8. HDU 1004 Let the Balloon Rise(STL初体验之map)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  9. hdu 1004 Let the Balloon Rise 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...

随机推荐

  1. Unity3D笔记四 基础知识概念

    1. Project视图 主要存放游戏中用到的所有资源文件,常见的包括:游戏脚本.预设.材质.动画.自定义字体.纹理.物理材质和GUI皮肤等. 1>     Folder: 文件夹,用于资源的分 ...

  2. angular -- ng-class该如何使用?

    ng-class是一个判断是否给某一个元素添加类名的属性: 例如:下面是判断 是否添加 aHover 这个类名: <ul class="nav fl w120 o"> ...

  3. ASP.NET网站性能优化

    如果你是一个做过ASP网站,又做过ASP.NET网站的程序员,你可能会发现,如果按正常的思路开发ASP.NET网站,ASP.NET网站的速度会比ASP网站慢很多,为什么强大的网站语言会比弱得慢的,原因 ...

  4. .Net 获取前端传递的数据

    1. DotNet MVC: form是用来获得表单提交的数据:querystring是用来获得标识在URL后面的所有返回的变量及其值. 比如常见的URL网页地址都有xxx.asp?pn=123456 ...

  5. slave have equal MySQL Server UUIDs原因及解决

    最近在部署MySQL主从复制架构的时候,碰到了"Last_IO_Error: Fatal error: The slave I/O thread stops because master a ...

  6. Doing Homework---hdu1074(状态压缩&&记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 有n(n<=15)门课需要做作业,每门课所需时间是used_time以及每门课作业上交的最 ...

  7. 百度领跑BAT all in O2O机遇大于挑战

        近期一年O2O可谓是互联网领域最"炙手可热"的话题,似乎是个创业项目都要和O2O沾点关系.所以我们看到各种细分O2O模式层出不穷,并且,似乎外卖.洗车.租房等传统服务已经通 ...

  8. mysql 数据操作 单表查询 concat()函数 定义显示格式

    #定义显示格式 concat() 函数用于连接字符串 类似于python 格式化操作print("姓名:%s" % name)或者 用,拼接一个一个的变量print("a ...

  9. HTML5游戏开发系列教程10(译)

    原文地址:http://www.script-tutorials.com/html5-game-development-lesson-10/ 最后我们将继续使用canvas来进行HTML5游戏开发系列 ...

  10. RabittMQ实践(一): RabbitMQ的安装、启动

    安装:   启动监控管理器:rabbitmq-plugins enable rabbitmq_management 关闭监控管理器:rabbitmq-plugins disable rabbitmq_ ...