2020牛客暑期多校训练营(第二场)D
Duration
https://ac.nowcoder.com/acm/contest/5667/D
题目描述
Given two moments on the same day in the form of HH:MM:SS, print the number of seconds between the two moments.
输入描述
Input two lines each contains a string in the form of , denoting a given moment.
输出描述
Only one line containing one integer, denoting the answer.
示例1
输入
12:00:00 17:00:00
输出
18000
示例2
输入
23:59:59 00:00:00
输出
86399
分析
以每天的 作为基准,分别算出两个时刻距离基准的时间间隔 ,两个时间间隔差的绝对值即为答案。
代码
/****************************************************************** Copyright: 11D_Beyonder All Rights Reserved Author: 11D_Beyonder Problem ID: 2020牛客暑期多校训练营(第二场) Problem D Date: 8/11/2020 Description: Easy Calculation *******************************************************************/ #include<iostream> #include<cmath> #include<cstdio> using namespace std; int main() { int HH,MM,SS; scanf("%d:%d:%d",&HH,&MM,&SS); int a=HH*3600+MM*60+SS; scanf("%d:%d:%d",&HH,&MM,&SS); int b=HH*3600+MM*60+SS; cout<<abs(a-b)<<endl; return 0; }
牛客暑期多校训练营题解 文章被收录于专栏
收集牛客暑期多校训练营的题解