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. web.xml的contextConfigLocation作用及自动加载applicationContext.xml

    web.xml的contextConfigLocation作用及自动加载applicationContext.xml 转自:http://blog.csdn.net/sapphire_aling/ar ...

  2. 并查集hdu4424

    Conquer a New Region Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. 【php】---mysql语法增、删、改、查---【巷子】

    1.mysql基本语法 001.增 语法:          insert into 表名 (列1,列2,列3) values(值1,值2,值3)     批量插入:插入insert-插入多行   语 ...

  4. 170616、解决 java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList

    报错截图: 原因:搭建项目的时候,springmvc默认是没有对象转换成json的转换器的,需要手动添加jackson依赖. 解决步骤: 1.添加jackson依赖到pom.xml <!-- j ...

  5. 让ASP.NET OutputCache使用http.sys kernel-mode cache

    在默认情况下,http.sys kerne mode cache只缓存静态文件. 那我们如何让ASP.NET OutputCache直接使用http.sys kerne mode cache?这样缓存 ...

  6. RSA算法原理与加密解密 求私钥等价求求模反元素 等价于分解出2个质数 (r*X+1)%[(p-1)(q-1)]=0

    Rsapaper.pdf http://people.csail.mit.edu/rivest/Rsapaper.pdf [概述Abstract 1.将字符串按照双方约定的规则转化为小于n的正整数m, ...

  7. xdotool xdotool模拟击键和鼠标移动--CutyCapt是一个截图工具,xvfb-run

    最近在做一个生成网站缩略图的功能,从网上查到相关资料,现与大家分享,xvfb这个软件,安装上之后一条命令就能执行此操作.很容易的就生成了自己想要的缩略图. xvfb-run -运行在一个虚拟的X服务器 ...

  8. CMDB三大绝招,助我站稳运维之巅

    上一篇(内功篇)介绍了建设CMDB的内功心法,接下来和各位交流下建设CMDB的招式.内功是根基.是基础,决定了武学修为境界的高低,招式也许就是明心见性之后的修行.修为指一个人的修养.素质.道德.涵养. ...

  9. 利用CombineFileInputFormat把netflix data set 导入到Hbase里

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/xiewenbo/article/details/25637931 package com.mr.te ...

  10. 【Cocos2dx 3.x Lua】TileMap使用

    1.编辑TileMap地图资源 2.Cocos2dx 3.x Lua中使用TileMap   Link: http://codepad.org/P0nFP1Dx  local TileMap=clas ...