【问题标题】:Suppress quotes in stdout (hackerrank)禁止标准输出中的引号(hackerrank)
【发布时间】:2019-12-27 10:28:39
【问题描述】:

我正在 Haskell 的 Hackerrank 中处理 string compression problem,并坚持使用 IO。我试图明确删除引号。

compress :: [Char] -> [Char]
compress = ...

main :: IO ()
main = do
    input <- getLine
    let result = compress input
    print $ filter (/='"') result 

代码编译并返回正确的响应,尽管用引号括起来。

Compiler Message
Wrong Answer

Input (stdin)
abcaaabbb

Your Output (stdout)
"abca3b3"

Expected Output
abca3b3

【问题讨论】:

  • 引号不在字符串的 content 中。这些在字符串的表示中,因为print 调用show

标签: haskell io stdout double-quotes


【解决方案1】:

你写:

putStrLn result

而不是最后一行:

 print $ filter (/='"') result

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 2016-09-24
    相关资源
    最近更新 更多