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/Others)
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.
green
red
blue
red
red
3
pink
orange
pink
0
pink
#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树的更多相关文章
- 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(map 用法样例)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- 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 ...
- 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 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应用)
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 ...
- hdu 1004 Let the Balloon Rise 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...
随机推荐
- 一键搞定JavaEE应用,JRE+Tomcat+Mysql-JaveEE绿色运行环境JTM0.9版 (转载)
这是一个集成了jre,tomcat,mysql的绿色运行环境, 直接解压之后就可以运行.不需要用户自己安装jre,tomcat,mysql,一键到位,看起来像是桌面式的web应用.换句话说,就像是we ...
- C# tostring 格式化输出
C 货币 2.5.ToString("C") ¥2.50 D 十进制数 25.ToString("D5") 00025 E 科学型 25000.ToString ...
- 数据字典Data Dict
数据字典 所有的数据表都属于数据库对象,每当创建一张数据表的时候,会自动在指定的数据字典表执行一个增加语句(这个增加语言我们是不知道的),数据字典的数据操作只能通过命令完成,不能直接使用SQL完成. ...
- Oracle Schema Objects——Synonyms
Oracle Schema Objects 同义词 同义词 = 表的别名. 现在假如说有一张数据表的名称是“USER1.student”,而现在又为这张数据表起了一个“USER1”的名字,以后就可以直 ...
- vs 开发常用快捷键
alt+shift+enter 编辑区最大化ctrl+] 括号匹配 ctrl+j 强迫智能感知ctrl+shift+空格 强迫智能感知(参数) ctrl+k+d ...
- uboot ping doesn’t work
Ping doesn't work Ping from U-Boot to a host should work. Ping from a host to U-Boot should not. U-B ...
- Python基础之软件目录结构规范
设计一个层次清晰的目录结构,就是为了达到这两点: 可读性高:不熟悉项目的人,一眼就能看懂目录结构. 可维护性高:随着时间的推移,代码/配置的规模增加,项目结构不会混乱,仍然能够组织良好. 目录组织方式 ...
- Day19 客户关系系统实战
day19 今日内容 Service事务 客户关系管理系统 Service事务 在Service中使用ThreadLocal来完成事务,为将来学习Spring事务打基础! 1 DAO中的事务 ...
- pathmunge
pathmunge是linux系统redhat系列版本系统变量/etc/profile中的函数 判断当前系统的PATH中是否有该命令的目录,如果没有,则判断是要将该目录放于PATH之前还是之后 pat ...
- 【Python】如何取到input中的value值?
练习:取到下方链接下所有海贼王的下载链接. # coding=utf-8 from selenium import webdriver from time import sleep import ke ...