题目描述
有一时钟在某时刻的时间为HH:MM:SS(24小时制),在经过一段时间(<24h)后,其时间变为hh:mm:ss 求其中经过了多少秒。
输入说明
第一行:输入时间HH:MM:SS
第二行:输入时间hh:mm:ss
输出说明
1行,为两时刻内经过的秒数。
输入样例1:
06:16:02
06:17:22
输出样例1:
80
输入样例2:
23:59:59
00:00:01
输出样例2:
2
思路:用hh2-hh1算出过了多少个小时,因为可能出现跨过24点的情况,所以需要结果+24然后取模h=(hh2-hh1+24)%24;
,然后用h*3600减去第一个时刻已经到达的时间,再加上第二个时刻已经到达的时间
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include <algorithm>
#include<string.h>
#include<math.h>
#define llu unsigned long long
using namespace std;
int main()
{
//cout << fixed << setprecision(0);
//cout << setw(8) << setiosflags(ios::left);
int hh1,mm1,ss1,hh2,mm2,ss2;
scanf("%d:%d:%d%d:%d:%d",&hh1,&mm1,&ss1,&hh2,&mm2,&ss2);
long long int h;
h=(hh2-hh1+24)%24;
h*=3600;
h=h+mm2*60+ss2-mm1*60-ss1;
cout << h << endl ;
return 0;
}