結果

問題 No.70 睡眠の重要性!
ユーザー mesh1nek0x0mesh1nek0x0
提出日時 2018-07-31 22:52:56
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 676 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 11,936 KB
実行使用メモリ 16,120 KB
最終ジャッジ日時 2023-10-19 20:33:38
合計ジャッジ時間 1,513 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
16,120 KB
testcase_01 AC 97 ms
16,120 KB
testcase_02 AC 86 ms
16,120 KB
testcase_03 AC 85 ms
16,120 KB
testcase_04 AC 88 ms
16,120 KB
testcase_05 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/bin/ruby
N = gets.chomp.to_i

sum = 0
N.times do |num|
  sleep_time, awake_time = gets.chomp.split(' ')
  a_h, a_m = awake_time.split(':')
  s_h, s_m = sleep_time.split(':')
  
  if a_h.to_i > s_h.to_i
    ## 起きた時間の方が大きい場合
    sum += (a_h.to_i * 60 + a_m.to_i) - (s_h.to_i * 60 + s_m.to_i)
    
  elsif a_h === s_h
    ## 時間が一緒なら分の差分だけ計算する
    sum += (a_m.to_i - s_m.to_i).abs
  else
    ## 寝た時間の方が大きいので寝た時間から24時までの時間+24時から起きるまでに時間
    sum += ((23 - s_h.to_i) * 60 + (60 - s_m.to_i))
    sum += (a_h.to_i * 60 + a_m.to_i)
  end  
end

puts sum
0