90分求救
查看原帖
90分求救
352553
MojaveHao楼主2024/3/2 15:18

代码如下

reduceDigit :: Int -> Int
reduceDigit n
  | n > 9     = reduceDigit $ sum $ map (read . (:[])) $ show n
  | otherwise = n

isLuckyNumber :: Integer -> Char
isLuckyNumber n
  | sum (zipWith transform [0..] (map (read . (:[])) $ show n)) `mod` 8 == 0 = 'T'
  | otherwise = 'F'
  where
    transform :: Int -> Int -> Int
    transform i x
      | even i    = x
      | otherwise = reduceDigit (x * 7)

main :: IO ()
main = do
  n <- readLn :: IO Int
  sequence_ [ readLn >>= putStrLn . (:[]) . isLuckyNumber | _ <- [1..n] ]
2024/3/2 15:18
加载中...