結果

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

テストケース

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

ソースコード

diff #

inputs = gets.split('/')
y = inputs[0].to_i # year
m = inputs[1].to_i # month
d = inputs[2].to_i # date

def last_date_of(year, month)
  thirty_days_month = [4, 6, 9, 11]
  thirtyone_days_month = [1, 3, 5, 7, 8, 10, 12]

  if thirty_days_month.include?(month)
    30
  elsif thirtyone_days_month.include?(month)
    31
  elsif year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)
    29
  else
    28
  end
end

after = 2 # 何日後の日付を答えとするか
last_date = last_date_of(y, m)
is_overflow = d + after > last_date

if is_overflow
  if m == 12
    # 12月で月が変わる場合
    ans_y = y + 1
    ans_m = 1
  else
    ans_y = y
    ans_m = m + 1
  end
  ans_d = d + after - last_date
else
  ans_y = y
  ans_m = m
  ans_d = d + after
end

answer = "#{ans_y.to_s.rjust(4, '0')}/#{ans_m.to_s.rjust(2, '0')}/#{ans_d.to_s.rjust(2, '0')}" 
puts answer

0