#P2830. Simulate Simple Array Operations

    ID: 16089 Type: Default 1000ms 256MiB

Simulate Simple Array Operations

Simulate Simple Array Operations

You are given a program consisting of several lines. Each line contains exactly one command. There are three types of commands:

  1. Declaration:
    int A[N]
    This declares an array named ( A ) of size ( N ) with indices from ( 0 ) to ( N-1 ) (where ( N\le100 )). All elements of the array are initially ( 0 ). The array name is a string of at most 10 letters. The size ( N ) will be given as an integer literal.

  2. Assignment:
    A[i] h
    This assigns the value ( h ) to the element at index ( i ) of array ( A ) (i.e. performs A[i] = h). Both ( i ) and ( h ) will be given as integer literals.

  3. Output:
    cout A[i]
    This command prints the value stored in ( A[i] ) (where ( A ) is an already declared array and ( i ) is a valid index).

    Note: All numbers used (e.g. in declaration, assignment, and index for output) are integer literals. You need to simulate the program by executing the commands in the order given. For each output command, print the number on a new line.

Input Format:
The input consists of several lines. Each line is one of the commands described above. There is no explicit limit on the number of commands; you should read until the end of input.

Output Format:
For each cout command, output the corresponding integer value on a separate line.

Example:

Input:
int a[5]
a[2] 10
a[4] 20
cout a[2]
cout a[4]

Output:
10
20

The problem requires you to simulate these simple array operations.

inputFormat

The input is given line by line. Each line is one of the three commands:

  1. Declaration: int A[N]
  2. Assignment: A[i] h
  3. Output: cout A[i]

You should process all lines until end-of-file.

outputFormat

For each output command (cout A[i]), print the integer value stored in that array at index ( i ). Each output should be on a new line.

sample

int a[5]
a[0] 3
a[4] 7
cout a[0]
cout a[4]
3

7

</p>