萌新刚学求助A+B

P1001 A+B Problem

樱初音斗橡皮 @ 2021-05-04 20:28:25

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


by ZBAA_MKC @ 2021-05-04 20:29:44

草,啥语言(


by 樱初音斗橡皮 @ 2021-05-04 20:30:27

@mkc20230729 Haskell


by ud2_ @ 2021-05-04 20:30:41

@樱初音斗橡皮 '\r'?


by 樱初音斗橡皮 @ 2021-05-04 20:31:51

@sjx233_ 啊。。。getLine 读进来的会有这些吗。。。


by 樱初音斗橡皮 @ 2021-05-04 20:32:22

艹,还真是


by Talaodi @ 2021-05-04 20:33:35

Haskell 这么多内建函数你为啥不用(

main :: IO ()
main = interact $ show . sum . map read . words

by Ew_Cors @ 2021-05-04 20:34:22

@Talaodi 手写快读(


by Maxmilite @ 2021-05-04 20:34:37

@樱初音斗橡皮

目测换行符

加与不加是两个结果

Input: 100000000 100000000\n

Output: 1099999965


by AFewMoon @ 2021-05-04 20:38:39

真·萌 新


by 樱初音斗橡皮 @ 2021-05-04 20:39:59

@Talaodi 没学过...


| 下一页