#include #include #include using namespace std; int main() { int pila[100]; int tope = 0; string instr; while (cin >> instr) { if (instr == "PUSH") { int val; cin >> val; pila[tope] = val; tope += 1; } else if (instr == "ADD") { if (tope < 2) { abort(); } int a = pila[tope - 1]; int b = pila[tope - 2]; tope -= 2; pila[tope] = a + b; tope += 1; } else if (instr == "PRINT") { if (tope < 1) { abort(); } int val = pila[tope - 1]; tope -= 1; cout << val << endl; } else if (instr == "DUP") { if (tope < 1) { abort(); } int val = pila[tope - 1]; pila[tope] = val; tope += 1; } else { cerr << "mala instruccion" << endl; abort(); } } }