結果

問題 No.18 うーさー暗号
ユーザー alpha_virginisalpha_virginis
提出日時 2016-05-04 14:53:08
言語 Haskell
(9.8.2)
結果
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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 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
          
0