zzulioj1015: 計算時間間隔

【題目描述】

讀入兩個用“時:分:秒”表示的時間點,計算以秒爲單位的時間間隔。

【輸入】

輸入有兩行,每行是一個用“時:分:秒”表示的時間點。測試數據保證第二個時間點晚於第一個時間點。

【輸出】

輸出一個整數,表示時間間隔的秒數。

【輸入樣例】

08:00:00
09:00:00

【輸出樣例】

3600

【C語言代碼】

#include<stdio.h>
int main(int argc,const char*argv[])
{
	 int h1,h2,m1,m2,s1,s2,a,b;
	scanf("%d:%d:%d",&h1,&m1,&s1);
	scanf("%d:%d:%d",&h2,&m2,&s2);
	a=h1*3600+m1*60+s1;
	b=h2*3600+m2*60+s2;
	printf("%d\n",b-a);
	return 0;
}

【python代碼】


import sys

import math

h1,m1,s1=map(int,input().split(":"))

h2,m2,s2=map(int,input().split(":"))

a=h1*3600+60*m1+s1

b=h2*3600+m2*60+s2

print(int(b-a))


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章