#P11738. Simulated Execution of Simplified C++ Programs

    ID: 13830 Type: Default 1000ms 256MiB

Simulated Execution of Simplified C++ Programs

Simulated Execution of Simplified C++ Programs

In this problem, you are given a piece of source code written in a simplified version of C++ along with its input data. The source code follows many restrictions to make its simulation feasible with brute force. In particular, the source always starts with the following three lines:

#include
#include
using namespace std;

The rest of the code is contained in int main() and may include variable declarations (all of type int or arrays of int), assignments, and basic control-flow statements such as if, while, and for. Input is performed via cin >> (int) and output via cout << (int) or putchar (with the guarantee that the argument is in the range $0\sim127$). Arithmetic, relational, and logical operations work as in C++ with their usual precedence. You may assume that all data and loops are small enough so that a brute force simulation is possible.

Your task is to simulate the execution of the provided source code with the given program input and then output the result produced by that code.

Input format: The first line contains an integer L indicating the number of lines in the source code. The following L lines contain the source code. The remaining part of the input contains the inputs for the simulated program.

Output format: Output the result generated by executing the provided source code on its input.

Note on expressions: If any formulas are present in your explanation, use LaTeX format. For example, integer constants and operations should be fully computed and follow the rules of C++ as described.

inputFormat

The input consists of two parts:

  1. An integer L on a single line, representing the number of lines in the source code.
  2. Next L lines: the simplified C++ source code.
  3. The remainder of the input provides the program input for the source code.

All tokens are separated by spaces or newlines.

outputFormat

Output exactly the output produced by the simulated source code after processing its input. No extra spaces or newlines should be added.

sample

8
#include
#include
using namespace std;
int main(){
 int a;
 cin >> a;
 cout << a;
}
42

Input for simulated program: 42

</p>