結果
問題 | No.419 直角三角形 |
ユーザー | alpha_virginis |
提出日時 | 2016-09-09 22:45:17 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 938 bytes |
コンパイル時間 | 6,583 ms |
コンパイル使用メモリ | 181,792 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-16 10:37:17 |
合計ジャッジ時間 | 7,407 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
コンパイルメッセージ
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
ソースコード
{-# LANGUAGE OverloadedStrings #-} import qualified Data.ByteString.Char8 as C import Data.Char import Text.Printf solve :: Int -> Int -> Double solve a b | a == b = sqrt $ x ** 2 + y ** 2 | otherwise = sqrt $ x ** 2 - y ** 2 where a2 = realToFrac a b2 = realToFrac b x = max a2 b2 y = min a2 b2 main :: IO () main = do ss <- C.getLine let (a, ss2) = nextInt ss let (b, ss3) = nextInt ss2 printf "%.20f\n" $ solve a b nextInt :: C.ByteString -> (Int, C.ByteString) nextInt ss | isDigit x || 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) | y == '-' = (-z,zs) | isDigit y = nextInt2 (n * 10 + (digitToInt y)) ys | otherwise = (n, ys) where y = C.head ss ys = C.tail ss (z,zs) = nextInt2 0 ys