#UVa:11677-Alarm Clock

灆洢 2016-04-20 21:57:27

直接算出第二個時間與第一個時間的時間差,若為負數表示其實還相隔了一整天,再加上24個小時即可得解。

C++(0.000)

/*******************************************************/
/* UVa 11677 Alarm Clock                               */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2016/04/20                                 */
/*******************************************************/
#include <iostream>
#include <cstdio>
using namespace std;

int main(){
  int H1, M1, H2, M2;
  while( scanf("%d%d%d%d", &H1, &M1, &H2, &M2) != EOF &&
         (H1 != 0 || M1 != 0 || H2 != 0 || M2 != 0 )){
    int minutes = (H2 - H1) * 60 + (M2 - M1);
    if( minutes < 0 ){
      minutes += 24 * 60;
    }

    printf("%d\n", minutes);
  }
  return 0;
}

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料