题目描述:
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 HH:MM:SS (00≤HH≤23,00≤MM,SS≤59), 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
题解:
题目的意思是给出两个时间,求出两个时间的时间秒差。
假设HH对应小时,MM对应分钟,SS对应秒,那么我们只需要将给出的时间都化为秒即可,即总秒数=HH图片说明 3600+MM图片说明 60+SS;然后我们输出两者秒数之差的绝对值即为答案。
AC代码如下
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
int read()
{
int sign=1,ans=0;
char ch;
ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
sign=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
ans=(ans<<1)+(ans<<3)+(ch^48);
ch=getchar();
}
return signans;
}
int main()
{
int a,b,c,d,e,f;
scanf("%d:%d:%d",&a,&b,&c);
scanf("%d:%d:%d",&d,&e,&f);
ll ansa=a
3600+b60+c;
ll ansb=d
3600+e*60+f;
if(ansa>ansb)
cout<<ansa-ansb<<'\n';
else
cout<<ansb-ansa<<'\n';
return 0;
}</queue></vector></string></cstdio></cstring></cmath></algorithm></iostream>