【ACM】hdu_1004_Let the Balloon Rise
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 57556 Accepted Submission(s): 21037
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.
hdu_1004_Let the Balloon Rise_201307271045.c
#include <stdio.h>
#include <string.h>
int main()
{
char str[1010][18];
int n;
while(scanf("%d",&n),n)
{
int i,j,k,m=0,num=0;
char str1[18],str2[18];
for(i=0;i<n;i++)
{
gets(str[i]);
}
for(j=1;j<n;j++)
for(i=0;i<n-j;i++)
if(strcmp(str[i],str[i+1])>0)
{
strcpy(str1,str[i]);
strcpy(str[i],str[i+1]);
strcpy(str[i+1],str1);
}
strcpy(str2,str[0]);
for(i=0;i<n;i++)
{
if(strcmp(str2,str[i])==0)
num++;
else
{
strcpy(str2,str[i]);
num=1;
if(num>m)
{
m=num;
k=i-1;
}
}
}
if(num>m)
{
m=num;
k=i-1;
}
printf("%s\n",str[k]);
}
return 0;
}
//超时
//参考代码如下:
#include <string.h>
int n, i, j, t, max, num[1000];
char color[1000][16];
while(scanf("%d", &n) != EOF){
if(n){
num[0]=0;
scanf("%s", color[0]);
for(i=1; i <n; i++){
num[i]=0;
scanf("%s", color[i]);
for(j=0; j <i-1; j++)
if(strcmp(color[i], color[j])==0) num[i] +=1;
}
max=num[0];
t=0;
for(i=1; i <n; i++)
if(max <num[i]) {max =num[i]; t=i;}
printf("%s\n",color[t]);
}
}
}
#include <string.h>
int main()
{
char str[1010][18];
int n;
while(scanf("%d",&n),n)
{
int i,j,k,max;
int num[1010]={0};
k=max=0;
for(i=0;i<n;i++)
{
scanf("%s",str[i]);
for(j=0;j<i;j++)
if(strcmp(str[i],str[j])==0)
num[i]++;
if(num[i]>max)
{
max=num[i];
k=i;
}
}
printf("%s\n",str[k]);
}
return 0;
}
【ACM】hdu_1004_Let the Balloon Rise的更多相关文章
- 【ACM】hdu_1004_Let the Balloon Rise_201308141026-2
Let the Balloon RiseTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
- 【ACM】HDU1008 Elevator 新手题前后不同的代码版本
[前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...
- 【ACM】魔方十一题
0. 前言打了两年的百度之星,都没进决赛.我最大的感受就是还是太弱,总结起来就是:人弱就要多做题,人傻就要多做题.题目还是按照分类做可能效果比较好,因此,就有了做几个系列的计划.这是系列中的第一个,解 ...
- 【ACM】那些年,我们挖(WA)过的最短路
不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大 ...
- 【Acm】算法之美—Crashing Balloon
题目概述:Crashing Balloon On every June 1st, the Children's Day, there will be a game named "crash ...
- 【ACM】不要62 (数位DP)
题目:http://acm.acmcoder.com/showproblem.php?pid=2089 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新 ...
- 【Acm】八皇后问题
八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题. 其解决办法和我以前发过的[算法之美—Fire Net:www.cnblogs.com/lcw/p/3159414.html]类似 题目:在8 ...
- 【ACM】hud1166 敌兵布阵(线段树)
经验: cout 特别慢 如果要求速度 全部用 printf !!! 在学习线段树 内容来自:http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/24 ...
随机推荐
- 0x6A 网络流初步
CH Round #17-C 这个算是一个技能点吧,不点不会,点了就没什么了.懒得写看书吧书上的1应该是0... 我又回来了太懒了不想翻书还是写写吧 必须边的判定条件:该边流量为0且两端的点在残余网络 ...
- multiple web application host under the same website on IIS (authentication mode)
第一种方式,修改forms的name how to set the forms authentication cookie path assume you have already solved th ...
- poj--1274--The Perfect Stall(匈牙利裸题)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21868 Accepted: 980 ...
- selenium3 + python - alert_is_present定位
from selenium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium ...
- 通过JS制作一个简易数码时钟
设计思路: 数码时钟即通过图片数字来显示当前时间,需要显示的图片的URL根据时间变化而变化. a.获取当前时间Date()并将当前时间信息转换为一个6位的字符串; b.根据时间字符串每个位置对应的数字 ...
- TPshop规格组合错误
TPshop规格组合错误 修改: admin/logic/goodslogic.class.php 中 方法:getSpecInput() 中 asort($spec_arr_sort) 去掉
- C#之考勤系统
闲来无聊,搞搞C#,下面就是我写的一个Demo 员工类 using System; using System.Collections.Generic; using System.Linq; using ...
- Windows7环境下Composer 安装包的Cache目录位置
http://segmentfault.com/a/1190000000355928 https://getcomposer.org/doc/ 要说Composer的用法,以后再说,现在只记录wind ...
- Android几种常见的多渠道(批量)打包方式介绍
多渠道打包,主要是为了统计不同的渠道上包的下载数量,渠道越多,我们需要打的包数量越多,这个时候,我们没法去使用单纯的手动打包去一个一个的生成不同的渠道包,我们需要更高效的打包方式. 声明渠道方式一: ...
- yar 调用rpc方法
<?php class RpcController extends Yaf_Controller_Abstract { //RPC入口 public function indexAction($ ...