hdu 1004 Let the Balloon Rise(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 90644 Accepted Submission(s):
34459
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.
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.
popular problem on a single line. It is guaranteed that there is a unique
solution for each test case.
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; struct node
{
node *next[];
int Count;
node()
{
for (int i=; i<; i++)
next[i]=NULL;
Count=;
}
}; char cc[];
node *p,*root=new node();
void insert(char *s)
{
p=root;
for (int i=; s[i]; i++)
{
int k=s[i]-'a';
if (p->next[k]==NULL)
p->next[k]=new node();
p=p->next[k];
}
p->Count++;
} int Search(char *s)
{
p=root;
for (int i=; s[i]; i++)
{
int k=s[i]-'a';
if (p->next[k]==NULL)
return ;
p=p->next[k];
}
//cout<<p->Count<<" "<<"3333333333"<<endl;
return p->Count;
} int main()
{
int t;
char ch[];
int Max;
while (~scanf("%d",&t))
{
Max=;
if (t==)
break;
while (t--)
{
scanf("%s",ch);
//gets(ch);
insert(ch);
int ans=Search(ch);
if (ans>Max)
{
Max=ans;
strcpy(cc,ch);
}
}
printf ("%s\n",cc);
}
return ;
}
hdu 1004 Let the Balloon Rise(字典树)的更多相关文章
- 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 ...
- hdu 1004 Let the Balloon Rise strcmp、map、trie树
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- 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 ...
- hdu 1004 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- 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 ...
- hdu 1004 Let the Balloon Rise 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...
- HDU 1004 - Let the Balloon Rise(map 用法样例)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- HDU 1004 Let the Balloon Rise(map应用)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- 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 ...
随机推荐
- web.config文件详解[转]
一).Web.Config是以XML文件规范存储,配置文件分为以下格式1.配置节处理程序声明特点: 位于配置文件的顶部,包含在<configSections>标志中.2.特定应用程序配置特 ...
- 相见恨晚的 scala - 01 [ 基础 ]
简洁到不行,多一个分号都是不应该. 学习笔记: centOS 下安装 scala 和安装 jdk 一毛一样 . 1 . 不同于 Java 的变量声明 :( 但是和 js 很像 ) /** * Crea ...
- .net core2.0入门使用EF
使用Nuget导入所需要的EF 核心包以及对应数据库的驱动包,我用的是sqlserver(.net 支持的所有数据库) Install-Package Microsoft.EntityFramewor ...
- java 一般类属性设置常量 用以长久使用
java 一般类属性设置常量 用以长久使用 一直引用 例如 文件名
- Hashtable 和 HashMap 以及 ConcurrentHashMap
备忘: ConcurrentHashMap与Hashtable的区别: Hashtable中采用的锁机制是一次锁住整个hash表,从而同一时刻只能由一个线程对其进行操作:而ConcurrentHash ...
- 关于字符编码:ascii、unicode与utf-8
转自:https://foofish.net/unicode_utf-8.html 阮一峰老师对普及计算机基础技术功不可没,但毕竟老师不是神,因此也避免不了对某些概念有一些错误的理解,<字符编码 ...
- web接口测试中需要测试的几个点
本文导读: web接口测试用例要包括欲测试的功能.应输入的数据和预期的输出结果,只有在数据能正确流入.流出模块的前提下,其他测试才有意义.下面介绍在web测试接口时一些需要注意的点 1.接口返回 数据 ...
- Swift中使用MPMoviePlayerController实现自定义视频播放器界面
默认情况下播放器自带各种控制按钮,比如前进后退播放暂停等: var url = NSBundle.mainBundle().URLForResource("1", withExte ...
- 如何在Eclipse 中查看(如Objects)的源代码
今天突然想看Objects的源码,结果失败了,总结了一下,贴出来. 一般查看源码的流程: 使用快捷键Ctri+Shit+T出现Open Type的对话框,在里面直接输入类名,回车就行: 在Eclips ...
- 洛谷 P1306 斐波那契公约数 解题报告
P1306 斐波那契公约数 题意:求\(Fibonacci\)数列第\(n\)项和第\(m\)项的最大公约数的最后8位. 数据范围:\(1<=n,m<=10^9\) 一些很有趣的性质 引理 ...