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 最近在做日志分 ...
随机推荐
- 使用uiautomator做UI测试
转载~~~~~~~~~~~~~~~~~~~~~~~~ 若有侵权,请及时联系本博主,博主将第一时间撤销 在Android 4.1发布的时候包含了一种新的测试工具–uiautomator,uiautoma ...
- Java类的基本运行顺序
不看不知道,一看还真吓了一跳!Java类的基本运行顺序你真的知道吗?如果你有疑惑,那就看下面这篇文章吧. 原文出自:[url]http://column.ibeifeng.com/chenchen ...
- Oracle常用日期函数
常用的时间格式掩码如下:掩码元素 含义YYYY 四位数年份 (如:2005) yearYY 二位数年份(如 05) Q ...
- 【转】PowerShell入门(七):管道——在命令行上编程
转至:http://www.cnblogs.com/ceachy/archive/2013/02/22/PowerShell_Pipeline.html 管道对于Shell来说是个化腐朽为神奇的东西, ...
- Android 开机启动
创建一个Receiver,用来监听开机完毕: public class MyReceiver extends BroadcastReceiver { static final String actio ...
- 关于ORACLE隐式转换后性能问题
SELECT TM.MONEY_CODE FROM T_CONTRACT_MASTER T,T_MONEY TM WHERE T.MONEY_ID = TM.MONEY_ID AND T.POLICY ...
- 浙江理工2015.12校赛-B 七龙珠
七龙珠 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 781 Solved: 329 Description 话说孙壕请吃了青岛大虾后,一下子变穷了,就 ...
- TCP/IP协议(二)
2014-09-04 11:03:27 注:关于seq 和 ack 的理解,seq为发送的字节的第一个序号,一直累加,ack接收字节的最后一个序号+1,建立连接和结束连接时的SYN.FIN标志位占 ...
- Oracle简单的函数语言
函数:这里的函数相当于java中写好的一些方法,有名字,可以传递参数,实现某一项具体功能. 函数分为: 1.单行函数 1.字符函数 2.日期函数 3.数字函数 4.转换函数 2.分组函数(后面的章节再 ...
- 20个Linux服务器安全强化建议(二)
接上文,继续介绍一些Linux服务器的安全配置. #6.强密码策略. 当我们使用 useradd.usermod 命令创建或维护用户账号时,确保始终应用强密码策略.例如,一个好的密码至少包括8个字 ...