我必须将输入读作:
1 <- number of lines next
10 20 30
2 <- number of lines next
5 5 5
6 8 9
0 <- terminating condition
输出应为:
output of f[(10,20,30)]
output of f[(5,5,5),(6,8,9)]
我还需要打印案例编号:
例如。
Case 1: ...
Case 2: ...
产生输出的函数有类型:
f :: [(Int,Int,Int)] -> Int
我用它作为:
loop = do
x <- getLine
if x == "0"
then return ()
else do arr <- replicateM (read x :: Int) getLine
let queries = map (read :: String -> Int) $ words $ unwords arr
print $ f $ pairUp queries;
loop
main = loop
pairUp :: [Int] -> [(Int,Int,Int)]
pairUp (0:0:0:_) = []
pairUp (n:m:o:rest) = (n,m,o) : (pairUp rest)
pairUp (_) = []
在一个测试用例后立即打印,但一直持续到0
有什么方法可以在最后打印输出?