結果

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

テストケース

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