对每组数据比较 e-c 与 r 的大小,输出 advertise / do not advertise / does not matter。
OJ: kattis
题目 ID: nastyhacks
难度:入门
标签:haskell
日期: 2026-07-10 14:27
题意
advertise,do not advertise,否则 → does not matter。
思路
纯条件判断。重点是用 Haskell 处理多组数据:getContents 一次读完,
递归分组每 3 个数一组处理。
代码
haskell
{-
Author by Rainboy blog: https://rainboylv.com github: https://github.com/rainboylvx
rbook: -> https://rbook.roj.ac.cn https://rbook2.roj.ac.cn
rainboy的学习导航网站: https://idx.roj.ac.cn
create_at: 2026-07-10 14:33
update_at: 2026-07-10 14:33
-}
solve r e c
| e - c > r = "advertise"
| e - c < r = "do not advertise"
| otherwise = "does not matter"
main = do
(_:rest) <- map read . words <$> getContents :: IO [Int]
let go [] = []
go (r:e:c:xs) = solve r e c : go xs
mapM_ putStrLn $ go rest复杂度
时间复杂度
总结
guard 三分支 + 模式匹配 (r:e:c:xs) 分组 + mapM_ putStrLn 输出。