poj 2501 Average Speed

简介:

这种题目一定要小心。很容易处理不好输入输出!

懒得写了,直接参考代码。。。这个代码写的很好,思路很清晰,风格跟我的也很接近


#include <stdio.h>

int main()
{
	int h,m,s,hh=0,mm=0,ss=0,speed=0;
	double distance=0;

	while(scanf("%d:%d:%d",&h,&m,&s)!=EOF)
	{
		distance+=(h-hh)*speed+(m-mm)*speed/60.0+(s-ss)*speed/3600.0;
		hh=h,mm=m,ss=s;

		if(getchar()==' ')
			scanf("%d",&speed);

		else
		{
			if(h<10)
				printf("0%d:",h);
			else printf("%d:",h);

			if(m<10)
				printf("0%d:",m);
			else printf("%d:",m);

			if(s<10)
				printf("0%d ",s);
			else printf("%d ",s);

			printf("%.2lf km\n",distance);
		}
	}
	return 0;
}



相关文章
|
机器学习/深度学习 数据挖掘 Python
使用Python实现Hull Moving Average (HMA)
赫尔移动平均线(Hull Moving Average,简称HMA)是一种技术指标,于2005年由Alan Hull开发。它是一种移动平均线,利用加权计算来减少滞后并提高准确性。
349 0
|
人工智能
codeforces 1092——F:Tree with Maximum Cost (树上DP)
codeforces 1092——F:Tree with Maximum Cost (树上DP)
94 0
POJ 2840 Big Clock
POJ 2840 Big Clock
94 0
POJ 2840 Big Clock
Description Our vicar raised money to have the church clock repaired for several weeks. The big clock, which used to strike the hours days...
887 0
|
机器学习/深度学习 人工智能
|
人工智能