結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー TomoProgTomoProg
提出日時 2018-10-10 22:48:37
言語 Ruby
(3.3.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 35 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-20 19:33:18
合計ジャッジ時間 2,404 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
12,288 KB
testcase_01 AC 82 ms
12,288 KB
testcase_02 AC 83 ms
12,288 KB
testcase_03 AC 78 ms
12,288 KB
testcase_04 AC 79 ms
12,160 KB
testcase_05 AC 78 ms
12,032 KB
testcase_06 AC 78 ms
12,288 KB
testcase_07 AC 77 ms
12,288 KB
testcase_08 AC 75 ms
12,032 KB
testcase_09 AC 78 ms
12,032 KB
testcase_10 AC 78 ms
12,160 KB
testcase_11 AC 78 ms
12,288 KB
testcase_12 AC 76 ms
12,288 KB
testcase_13 AC 77 ms
12,032 KB
testcase_14 AC 77 ms
12,160 KB
testcase_15 AC 78 ms
12,160 KB
testcase_16 AC 77 ms
12,160 KB
testcase_17 AC 78 ms
12,160 KB
testcase_18 AC 77 ms
12,288 KB
testcase_19 AC 75 ms
12,288 KB
testcase_20 AC 76 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

monthly_last_days = {
  1 => 31,
  2 => 28,
  3 => 31,
  4 => 30,
  5 => 31,
  6 => 30,
  7 => 31,
  8 => 31,
  9 => 30,
  10 => 31,
  11 => 30,
  12 => 31,
}

# うるう年判定
def check_leap_year(year)
  if year % 400 == 0
    true
  elsif year % 4 == 0 && year % 100 == 0
    false
  elsif year % 4 == 0
    true
  else
    false
  end
end

# 入力受付
year, month, day = gets.split('/').map(&:to_i)

# うるう年の場合は2月の最終日を変更
monthly_last_days[2] = 29 if check_leap_year(year)

# メインロジック
if (day + 2) > monthly_last_days[month]
  day = (day + 2) % monthly_last_days[month]
  month += 1
  if month > 12
    month = month % 12
    year += 1
  end
else
  day += 2
end

# 回答
puts "#{year}/#{month.to_s.rjust(2, '0')}/#{day.to_s.rjust(2, '0')}"
0