You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeForce-A. Way Too Long Words测试用例1报错本地运行正常求助

问题原因

  • 你没有适配题目的标准输入格式:该题第一行输入为整数t,代表后续待处理的单词总数,接下来才是t行独立的待处理单词。你当前的代码仅读取了第一行的整数t作为待处理字符串,也没有循环处理后续的所有单词,自然会在测试用例上报错。
  • 本地运行时你大概率是直接输入单词测试,跳过了第一行的测试用例数字,才会出现本地运行正常、提交报错的差异。

修正后可正常提交的代码

function main() {
  // 先读取测试用例数量
  const t = parseInt(readline());
  // 循环处理每个单词
  for (let i = 0; i < t; i++) {
    const word = readline();
    if (word.length < 11) {
      console.log(word);
    } else {
      const abbreviated = `${word[0]}${word.length - 2}${word[word.length - 1]}`;
      console.log(abbreviated);
    }
  }
}

内容的提问来源于stack exchange,提问作者Md Iqbal Hossain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 21:45:08