P1739 #3 是不是有毒啊,RE
查看原帖
P1739 #3 是不是有毒啊,RE
183501
RMOlive楼主2021/11/4 18:54

P1739是不是有毒啊 #3 RE

lengthS :: String -> Int -> Bool
lengthS "" n = n == 0
lengthS s n
  | n < 0 = False
  | head s == '(' = lengthS (tail s) (n + 1)
  | head s == ')' = lengthS (tail s) (n - 1)
  | otherwise = lengthS (tail s) n

main :: IO()
main = do
    src <- getLine
    putStrLn $ if lengthS src 0 then "YES" else "NO"

2021/11/4 18:54
加载中...