結果
| 問題 |
No.18 うーさー暗号
|
| コンテスト | |
| ユーザー |
alpha_virginis
|
| 提出日時 | 2016-05-04 14:53:08 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,251 bytes |
| コンパイル時間 | 8,304 ms |
| コンパイル使用メモリ | 180,916 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-07 06:08:00 |
| 合計ジャッジ時間 | 8,953 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
コンパイルメッセージ
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
ソースコード
import qualified Data.ByteString.Char8 as C
import Data.Char
import Data.Array.IO
main :: IO ()
main = do
ss <- C.getLine
xs <- newArray (0, 2000) '\0' :: IO(IOUArray Int Char)
solve 0 ss xs
printss 0 (C.length ss) xs
putStrLn ""
printss :: Int -> Int -> IOUArray Int Char -> IO ()
printss i n xs = if i >= n then return() else printss2 i n xs
printss2 :: Int -> Int -> IOUArray Int Char -> IO ()
printss2 i n xs = do
c <- readArray xs i
putChar c
printss (i + 1) n xs
solve :: Int -> C.ByteString -> IOUArray Int Char -> IO ()
solve n ss xs
| C.length ss <= n = return ()
| otherwise = solve2 n ss xs
solve2 :: Int -> C.ByteString -> IOUArray Int Char -> IO ()
solve2 n ss xs = do
let n2 = n + 1
let d = mod n2 26
let c = C.index ss n
let x = mod (ord c - ord 'A' + 26 - d) 26 + ord 'A'
writeArray xs n (chr x)
solve (n + 1) ss xs
nextInt :: C.ByteString -> (Int, C.ByteString)
nextInt ss
| isDigit x = nextInt2 0 ss
| otherwise = nextInt $ C.tail ss
where x = C.head ss
nextInt2 :: Int -> C.ByteString -> (Int, C.ByteString)
nextInt2 n ss
| C.null ss = (n, ss)
| isDigit y = nextInt2 (n * 10 + (digitToInt y)) ys
| otherwise = (n, ys)
where y = C.head ss
ys = C.tail ss
alpha_virginis