結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー 情報学生
提出日時 2019-08-20 09:59:01
言語 Haskell
(9.10.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,350 bytes
コンパイル時間 2,686 ms
コンパイル使用メモリ 171,520 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-06 11:43:16
合計ジャッジ時間 2,692 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.List.Split
import Text.Printf

is_leap_year :: Int -> Bool
is_leap_year yy
    | yy `mod` 400 == 0 = True
    | yy `mod` 100 == 0 = False
    | yy `mod`   4 == 0 = True
    | otherwise         = False

is28 :: [Int] -> Bool
is28 [yy, mm, dd]
    | (not $ is_leap_year yy) && mm == 2 = True
    | otherwise                          = False

is29 :: [Int] -> Bool
is29 [yy, mm, dd]
    | is_leap_year yy && mm == 2 = True
    | otherwise                  = False

is30 :: [Int] -> Bool
is30 [yy, mm, dd]
    | elem mm [4, 6, 9, 11] = True
    | otherwise             = False

is31 :: [Int] -> Bool
is31 [yy, mm, dd]
    | elem mm [1, 3, 5, 7, 8, 10, 12] = True
    | otherwise                       = False

main :: IO ()
main = getLine >>= solve

solve :: String -> IO ()
solve s = printf "%d/%02d/%02d" yy mm dd
    where
        [y, m, d] = map (read :: String -> Int) $ splitOn "/" s
        [yy, mm, dd] = g [y, m, d]

g :: [Int] -> [Int]
g xs@[y,m,d]
    | d <= 26 = [y, m, d + 2]
    | is28 xs = [y, m + 1, (d + 2) `mod` 28]
    | is29 xs = if d == 27 then [y, m, d + 2] else [y, m + 1, (d + 2) `mod` 29]
    | is30 xs = if d <= 28 then [y, m, d + 2] else [y, m + 1, (d + 2) `mod` 30]
    | is31 xs && m == 12 && d >= 30 = [y + 1, 1, (d + 2) `mod` 31]
    | otherwise = if d <= 29 then [y, m, d + 2] else [y, m + 1, (d + 2) `mod` 31]
0