Duration

Duration

题意:

给你两个时间问相差多少秒?

题解:

A: 这题直接把 时间换成秒相减就行了吧!

B:是的!听说py3行

代码:

#include <bits/stdc++.h>
using namespace std;
 
string a, b;
 
int gettime(string s) {
    int h = 0, m = 0, ss = 0;
    for(int i = 0;i <= 1; i++) {
        h *= 10; h += s[i]-'0';
    }
    for(int i = 3;i <= 4; i++) {
        m *= 10; m += s[i]-'0';
    }
    for(int i = 6;i <= 7; i++) {
        ss *= 10; ss += s[i];
    }
    return ss+m*60+h*3600;
}
 
int main() {
    cin >> a >> b;
    int t1 = gettime(a);
    int t2 = gettime(b);
    if(t1 > t2) swap(t1, t2);
    printf("%d\n", t2-t1);
}
posted @ 2020-07-14 01:00  ccsu_zhaobo  阅读(240)  评论(0)    收藏  举报