#P2830. 写程序
写程序
Description
There is a program with several lines, and each line contains exactly one command. The possible commands are as follows:
int a[N]Declare an array. The keyword is alwaysint, never something else likelong long.adenotes the name of an array (not necessarilya; it could be another letter or multiple letters, with length no more than ). After that is a pair of brackets containing either a number or a variable, indicating the array size (indices range from to , ). After the array is declared, all its elements are .a[i] hAssignhtoa[i](i.e.,a[i]=h). Here can be either a number or a variable, and can be either a number or a variable.cout hOutput , where must be a variable.
Input Format
Several lines: one command per line.
Output Format
For each output command (i.e., cout), print one line.
If an out-of-bounds array index is found on any line (note that only this type of error can occur; there will not be other issues such as redefinition), stop immediately regardless of how many commands remain below, ignore all remaining commands, and output -1.
int a[10]
a[a[0]] 2
cout a[0]
2
int a[10]
a[0] 10
cout a[0]
a[a[0]] 1
cout a[0]
10
-1
Hint
The number of lines does not exceed . Variables may be nested, such as a[a[b[0]]], etc. Uppercase letters may also appear. All numbers that appear do not exceed , are not negative, and are not decimals.
Translated by ChatGPT 5
京公网安备 11011102002149号