北郵OJ-89. 統計時間間隔-13網研上機B

  1. 統計時間間隔
    時間限制 1000 ms 內存限制 65536 KB
    題目描述
    給出兩個時間(24小時制),求第一個時間至少要經過多久才能到達第二個時間。給出的時間一定滿足的形式,其中x和y分別代表小時和分鐘。0≤x<24,0≤y<60。
    輸入格式
    第一行爲數據組數T(1≤T≤50000)。
    每組數據包括兩行,分別代表兩個時間

輸出格式
每組數據輸出一行,表示最少經過的分鐘數。

輸入樣例
2
7:00
7:00
7:00
8:00
輸出樣例
0
60

#include <iostream>
#include <cstdio>
using namespace std;

int main(){
    int t;
    int h1,h2,m1,m2;
    int time1,time2,dif;
    scanf("%d",&t);
    while (t--){
        //input && initiate
        scanf("%d:%d",&h1,&m1);
        scanf("%d:%d",&h2,&m2);
        //cal
        time1=h1*60+m1;
        time2=h2*60+m2;
        if (time1<=time2)
            dif=time2-time1;
        else
            dif=24*60-(time1-time2);
        //output
        printf("%d\n",dif);
        //debug**
//      cout<<h1<<endl<<m1<<endl<<h2<<endl<<m2<<endl;
//      return true;
        //*******
    }

    return true;
} 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章