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. Add a try-catch with Mono Cecil

    Adding exception handlers with Mono.Cecil is not difficult, it just requires you to know how excepti ...

  2. postgresql----LIKE和SIMILAR TO

    LIKE和SIMILAR TO都支持模糊查询,另外SIMILAR TO还支持正则表达式查询.模糊查询中有两个重要的符号:下划线'_'匹配任意单个字符,百分号'%'匹配任意多个字符,可以是0个,如果想匹 ...

  3. HOJ 2226&POJ2688 Cleaning Robot(BFS+TSP(状态压缩DP))

    Cleaning Robot Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4264 Accepted: 1713 Descri ...

  4. Oracle卸载之正确卸载rac数据库的方法(MOS卸载方法)

    一.关闭数据库和资源 1.节点1 [root@node1 bin]# pwd /u01/app/11.2.0/grid/bin [root@node1 bin]# ./crsctl stop crs ...

  5. acceptorThreadCount

    Apache Tomcat 7 Configuration Reference (7.0.92) - The HTTP Connector https://tomcat.apache.org/tomc ...

  6. python调用C++之pybind11入门(相互调用)

    python调用C/C++有不少的方法,如boost.python, swig, ctypes, pybind11等,这些方法有繁有简,而pybind11的优点是对C++ 11支持很好,API比较简单 ...

  7. Python开发【笔记】:“~” 按位取反运计算方法

    按位取反: 要弄懂这个运算符的计算方法,首先必须明白二进制数在内存中的存放形式,二进制数在内存中是以补码的形式存放的 原码 原码(true form)是一种计算机中对数字的二进制定点表示方法.原码表示 ...

  8. SQL基础--查询之四--集合查询

    SQL基础--查询之四--集合查询

  9. (1.5)DML增强功能-try catch及事务控制

    一.事务控制与Try Catch结合 当 SET XACT_ABORT 为 ON 时,如果执行 Transact-SQL 语句产生运行时错误,则整个事务将终止并回滚. 当 SET XACT_ABORT ...

  10. Spring源码解析(三)BeanDefinition的载入、解析和注册

    通过上一篇源码的分析已经完成了BeanDefinition资源文件的定位,本篇继续分析BeanDefinition资源文件的载入和解析. AbstractBeanDefinitionReader的lo ...