Duration


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;
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

幸愉信奥

谢谢亲的支持,我会继续努力啦~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值