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. 【BZOJ4003】[JLOI2015]城池攻占 可并堆

    [BZOJ4003][JLOI2015]城池攻占 Description 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池. 这 n 个城池用 1 到 n 的整数表示.除 1 号 ...

  2. sqlserver字符串多行合并为一行

    --创建测试表 CREATE TABLE [dbo].[TestRows2Columns]( [Id] [,) NOT NULL, [UserName] [nvarchar]() NULL, [Sub ...

  3. 向Docx4j生成的word文档中添加布局--第二部分

    原文标题:Adding layout to your Docx4j-generated word documents, part 2 原文链接:http://blog.iprofs.nl/2012/1 ...

  4. Spring 体系结构

    https://www.w3cschool.cn/wkspring/dcu91icn.html 体系结构 Spring 有可能成为所有企业应用程序的一站式服务点,然而,Spring 是模块化的,允许你 ...

  5. 双态运维联盟(BOA)正式成立

    3月1日,由联想.新华三.华为等12家IT企业在北京正式达成协议,联合发起成立“双态运维联盟”.中国电子工业标准技术协会.信息技术服务分会数据中心运营管理工作组(DCMG)组长肖建一先生出席了会议. ...

  6. java-mybaits-009-mybatis-spring-使用,SqlSessionFactoryBean、事务

    一.版本限制 参看地址:http://www.mybatis.org/spring/ 二.使用入门 2.1.pom <dependency> <groupId>org.myba ...

  7. React Native入门-刘望舒

    React Native入门(一)环境搭建与Hello World React Native入门(二)Atom+Nuclide安装.配置与调试 React Native入门(三)组件的Props(属性 ...

  8. 10.numpy基本用法

    参考: https://blog.csdn.net/sinat_32547403/article/details/54017551

  9. Exception in thread "main" java.lang.NoClassDefFoundError: scala/Product$class

    在使用spark sql时一直运行报这个错误,最后仔细排查竟然是引入了两个scala library .去除其中一个scala的编译器即可 Exception in thread "main ...

  10. SpringData环境搭建代码编写

    首先我们在前面的两节已经了解了SpringData是干什么用的?那我们从这节开始我们就开始编码测试SpringData. 1:首先我们从配置文件开始,我们首先需要写一个连接数据库的文件db.prope ...