萌新刚学求助A+B
查看原帖
萌新刚学求助A+B
66287
樱初音斗橡皮楼主2021/5/4 20:28
import Data.Char

foldl' :: (b -> a -> b) -> b -> [a] -> b
foldl' _ acc [] = acc
foldl' f acc (x:xs) = foldl' f (f acc x) xs

atoi :: String -> Int
atoi ('-':xs) = -atoi xs
atoi s = foldl' (\acc x -> (acc * 10 + (ord x - ord '0'))) 0 s

split :: String -> (String, String)
split (' ':xs) = ([], xs)
split (x:xs) = (x:(fst ans), snd ans) where ans = split xs

main :: IO()
main = do
	input <- getLine
	let (a, b) = split input
	let i = atoi a
	let j = atoi b
	print (i + j)

RT,本机和在线 ide 都试过了,都没问题,一提交全 WA

2021/5/4 20:28
加载中...