Firmware frequently sends diagnostic and debug messages to external systems.
Depending on system configuration or hardware availability, the same firmware image may need to transmit logs over different communication transports such as UART or SPI.
The logging logic must not depend on transport-specific details like registers, flags, or framing rules.
Instead, logging must be performed through a runtime-selected stream abstraction, allowing the transport to be changed without modifying application logic.
Your task is to complete the design so that log messages are written through an abstract output stream selected at runtime.
The application logic must remain completely independent of the chosen transport.
Program Flow:
Input Format:
Input is provided via standard input (stdin).
1 → UART transport2 → SPI transport1 ≤ N ≤ 10Output Format:
For UART:
UART:<message> For SPI:
SPI:<message> Rules:
main() must not be modifiedExample:
Example 1
Input:
1 3
SystemOK
TempHigh
Reset Output:
UART:SystemOK
UART:TempHigh
UART:Reset Example 2
Input:
2
2
Ping
Pong
Output:
SPI:Ping
SPI:Pong
Constraints:
Input
1 2 Hello World
Expected Output
UART:Hello UART:World