Duration
题目描述
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 ≤ \leq ≤ HH ≤ \leq ≤ 23, 00 ≤ \leq ≤ MM,SS ≤ \leq ≤ 59)HH:MM:SS (00≤HH≤23,00≤MM,SS≤59), denoting a given moment.
输出描述
Only one line containing one integer, denoting the answer.
输入样例
12:00:00
17:00:00
输出样例
18000
#include <iostream>
using namespace std;
typedef long long ll;
string s,t;
int a[5],b[5];
int main()
{
ios::sync_with_stdio(false),cin.tie(0);
cin>>s>>t;
int len=s.size(),vs=0,vt=0;
int idx=0,f=0;
for(int i=0;i<len;++i)
{
if(s[i]==':') ++i;
if(s[i]>='0'&&s[i]<='9'){
vs =vs*10+s[i]-'0';
vt=vt*10+t[i]-'0';
f++;
}
if(f==2)
{
f=0;
a[idx]=vs;
b[idx++]=vt;
vs=0,vt=0;
}
}
// for(int i=0;i<idx;i++) cout<<a[i]<<endl;cout<<endl;
// for(int i=0;i<idx;i++) cout<<b[i]<<endl;cout<<endl;
ll res=0;
ll x=a[0]*3600+a[1]*60+a[2];
ll y=b[0]*3600+b[1]*60+b[2];
if(x>y) res=x-y;
else res=y-x;
cout<<res<<'\n';
return 0;
}
4382

被折叠的 条评论
为什么被折叠?



