P28629 [洛谷] Writing a Program
提高-
题目描述

Background

zrz is writing a program and asks you to check if there are any issues with it.

Problem Description

There is a program consisting of several lines, with each line containing only one command. The possible commands are as follows:

  • int a[maxn]: Declares an array. The beginning is always int, not something like longlong. a is the name of an array (it might not be a, but could be another letter or multiple letters, with a maximum length of 10). Following is a pair of brackets and a number or variable, indicating the array size (ranging from 0 to maxn-1, where maxn <= 100). After declaration, all elements in the array are initialized to 0.

  • a[i] h: Assigns h to a[i] (i.e., a[i] = h). Here, h could be a number or a variable, and i represents a number or a variable.

  • cout h: Outputs h, where h is definitely a variable.

Input and Output Formats

Input Format

Several lines, each containing one command.

Output Format

For each output command (cout), output one line. If an array index out-of-bounds error is detected on any line, immediately halt execution, ignoring all subsequent commands, and output -1.

Sample Input and Output

Sample Input #1

int a[10]
a[a[0]] 2
cout a[0]

Sample Output #1

2

Sample Input #2

int a[10]
a[0] 10
cout a[0]
a[a[0]] 1
cout a[0]

Sample Output #2

10
-1

Notes

The number of lines will not be excessive. Variables may be nested, such as a[a[b[0]]], and may include uppercase letters. All numbers will not exceed 10^9, will not be negative, and will not be decimal.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
int a[10] a[a[0]] 2 cout a[0]
样例输出
2