QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#856847#9917. The Story of Emperor BieCrysflyCompile Error//Haskell737b2025-01-14 17:47:372025-01-14 17:47:39

Judging History

你现在查看的是最新测评结果

  • [2025-01-14 17:47:39]
  • 评测
  • [2025-01-14 17:47:37]
  • 提交

answer

import Data.List (maximum, elemIndices)
import Control.Monad (replicateM)

-- 读取一个整数
readInt :: IO Int
readInt = readLn

-- 读取一行整数列表
readInts :: IO [Int]
readInts = fmap (map read . words) getLine

-- 处理每个测试用例
work :: IO ()
work = do
    n <- readInt          -- 读取数组大小
    a <- readInts         -- 读取数组
    let mx = maximum a    -- 找到最大值
    let indices = map (+1) (elemIndices mx a) -- 找到最大值的位置(从 1 开始)
    putStrLn $ unwords $ map show indices

-- 主函数
main :: IO ()
main = do
    t <- readInt                      -- 读取测试用例数
    replicateM t work                 -- 处理每个测试用例

详细


<no location info>: warning:
    -XGeneralizedNewtypeDeriving is not allowed in Safe Haskell; ignoring -XGeneralizedNewtypeDeriving
[1 of 2] Compiling Main             ( answer.hs, answer.o )

answer.hs:25:5: error:
    • Couldn't match type ‘[()]’ with ‘()’
      Expected: IO ()
        Actual: IO [()]
    • In a stmt of a 'do' block: replicateM t work
      In the expression:
        do t <- readInt
           replicateM t work
      In an equation for ‘main’:
          main
            = do t <- readInt
                 replicateM t work
   |
25 |     replicateM t work                 -- 处理每个测试用例
   |     ^^^^^^^^^^^^^^^^^