hdu 1036 (I/O routines, fgets, sscanf, %02d, rounding, atoi, strtol) 分类: hdoj 2015-06-16 19:37 32人阅读 评论(0) 收藏
thanks to http://stackoverflow.com/questions/2144459/using-scanf-to-accept-user-input and http://stackoverflow.com/questions/456303/how-to-validate-input-using-scanf for the i/o part.
thanks to http://www.haodaima.net/art/137347 for the rounding part. s=s/nkilo+0.5; //s=round(s/nkilo);
check return value of scanf,
std::fgets, http://en.cppreference.com/w/cpp/io/c/fgets
std::atoi, std::atol, std::atoll,
std::strtof, std::strtod, std::strtold,
std::strtol, std::strtoll,
std::strtok, http://en.cppreference.com/w/cpp/string/byte/strtok
std::round, std::lround, std::llround, http://en.cppreference.com/w/cpp/numeric/math/round
#include <cstdio>
#include <cmath>
#include <algorithm>
#define MAXLEN 200
#define STEP 8
char buffer[MAXLEN];
int main() {
//freopen("input.txt","r",stdin);
int nsect, team, h,m,s, ht,mt,st, i, disqualified;
char *p;
double nkilo;
scanf("%d%lf",&nsect,&nkilo);
while(scanf("%d",&team)==1) {
h=m=s=0; disqualified=0;
p=buffer;
fgets(buffer,MAXLEN,stdin);
for(i=0;i<nsect;++i) {
if(sscanf(p,"%d:%d:%d",&ht,&mt,&st)!=3) { disqualified=1; break; }
h+=ht; m+=mt; s+=st; p+=STEP;
}
if(disqualified) { printf("%3d: -\n",team); continue; }
s+=(m*60+h*3600);
s=s/nkilo+0.5; //s=round(s/nkilo);
m=s/60; s=s%60;
printf("%3d: %d:%02d min/km\n",team,m,s);
}
return 0;
}
as the problem title of hdu 1036 ( Average is not Fast Enough! )
suggest, Average is not Fast Enough, indeed.
版权声明:本文为博主原创文章,未经博主允许不得转载。// p.s. If in any way improment can be achieved, better performance or whatever, it will be well-appreciated to let me know, thanks in advance.
hdu 1036 (I/O routines, fgets, sscanf, %02d, rounding, atoi, strtol) 分类: hdoj 2015-06-16 19:37 32人阅读 评论(0) 收藏的更多相关文章
- hdu 1053 (huffman coding, greedy algorithm, std::partition, std::priority_queue ) 分类: hdoj 2015-06-18 19:11 22人阅读 评论(0) 收藏
huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commente ...
- Let the Balloon Rise 分类: HDU 2015-06-19 19:11 7人阅读 评论(0) 收藏
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1532 Drainage Ditches 分类: Brush Mode 2014-07-31 10:38 82人阅读 评论(0) 收藏
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDU 1754 I Hate It 2016-09-14 19:01 27人阅读 评论(0) 收藏
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Bzoj 1036 树的统计 分类: ACM TYPE 2014-12-29 18:55 72人阅读 评论(0) 收藏
Description 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w.我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. Q ...
- sscanf 函数 分类: POJ 2015-08-04 09:19 4人阅读 评论(0) 收藏
sscanf 其实很强大 分类: 纯C技术 技术笔记 2010-03-05 16:00 12133人阅读 评论(4) 收藏 举报 正则表达式stringbuffercurlgoogle 最近在做日志分 ...
随机推荐
- 二、Java基础--02
作为本人首篇黑马技术博客有必要交代一下背景.个人理解博客的用作在于于己在于交流,于他在于学习,在交流学习中共同成长.下面进入正题.本文主要是介绍在做黑马入门测试时的一些问题(这个应该不是泄露题库吧). ...
- 自定义view imageviw
新建一个类继承imageview package com.exaple.myselfview; import android.content.Context; import android.graph ...
- Java Spring DI之旅
做过.NET的人很多都用过Microsoft Enterprise Library,里面有一个Dependency injection工具Unity,我们可以使用它来实现依赖注入:什么是依赖注入呢?我 ...
- IE8 下 select option 内容过长 , 展开时信息显示不全解决办法
IE8 下 select option 内容过长 , 展开时信息显示不全 , 简单折衷的方式就是给 option 加上 title 属性 , 但是又不想一个个的修改,怎么办呢,代码如下 : //sel ...
- wex5 教程之 图文讲解 Cloudx5一键部署
视频教程地址:http://v.youku.com/v_show/id_XMTc3OTExNTUwNA==.html 效果预览: 一键部署cloudx5三要领 1.数据源命名为x5 2.数据库命名为x ...
- python 笔记
第一周2016/9/11 Python 2.0和3.0的区别 3.0 的模块名改了和之前的2.0 不一样 #!/usr/bin/env python # -*- coding:utf-8 -*- ...
- python 学习笔记十一 SQLALchemy ORM(进阶篇)
SqlAlchemy ORM SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数据A ...
- EXCEL计算数字、汉字、英文单元格的计数
1.数字COUNT(A1:A100)2.汉字{=SUMPRODUCT(IF(LEN(A1:A100)LENB(A1:A100),1,0)*1)}3.英文{=SUMPRODUCT(IF(ISTEXT(A ...
- HTML新手向
一:[什么是HTML] HTML全名是Hyper Test Markup language,是超文本标记语言,用来创建和其他在网页浏览器中看到的信息(由排版语言演变而来)它是用来说明页面排版方式的标记 ...
- centos7 docker mysql56
yum -y install docker docker pull centos docker run --name=mysqltmp -i -t centos /bin/bash yum -y in ...