cswork / OA打开练习工作台

OpenAIOA #4

ChatApp with Bots

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)迭代器设计模拟/实现

Implement a small in-memory chat application that supports multiple channels and extensible bots. Each channel maintains its own message history and any bot state associated with that channel. The design should allow new bot types to be added without modifying the core chat logic. For this problem, process a list of commands:

  • REGISTER botName ...: register one or more bots
  • SEND channelId userId text...: append the user message to that channel and then append any bot replies triggered by the message
  • PRINT channelId: emit the full message history for that channel in order Assume two example bots exist: EchoBot replies with the same text it receives, and HelpBot replies with a help string when the message text is help. Function Description Complete the function runChatAppCommands in the editor below. runChatAppCommands has the following parameter:
  • String[] commands: the commands to process in order Returns String[]: the lines produced by all PRINT commands, in order.

Constraints

  • 1 ≤ commands.length ≤ 10⁵
  • The number of channels is at most 10⁴.
  • The number of registered bots is at most 10².
  • Commands arrive sequentially; no concurrency handling is required.