• + 0 comments

    Haskell

    module Main where
    
    import Data.Char (chr, isAlpha, isUpper, ord)
    
    rot :: Int -> Char -> Char
    rot n c
        | not (isAlpha c) = c
        | isUpper c = chr $ ord 'A' + (ord c - ord 'A' + n) `mod` 26
        | otherwise = chr $ ord 'a' + (ord c - ord 'a' + n) `mod` 26
    
    solve :: Int -> String -> String
    solve n = map (rot n)
    
    main :: IO ()
    main = do
        _ <- getLine
        s <- getLine
        n <- readLn :: IO Int
        putStrLn $ solve n s