#include <iostream> // Global command functions void cmdReset() { std::cout << "System Reset" << std::endl; } void cmdStart() { std::cout << "System Start" << std::endl; } void cmdStop() { std::cout << "System Stop" << std::endl; } int main() { void (*dispatchTable[])() = {cmdReset, cmdStart, cmdStop}; int N; if (!(std::cin >> N)) return 0; for (int i = 0; i < N; ++i) { int cmdID; std::cin >> cmdID; if(cmdID >= 0 && cmdID < 3){ dispatchTable[cmdID](); } else{ std::cout << "Invalid Command" << std::endl; } } return 0; }
Test Cases
Test Results
Input
3 1 0 5
Expected Output
System Start System Reset Invalid Command