-->
当前位置:首页 > 题库

PROGRAMMING:Tuple

Luz5年前 (2021-05-10)题库568
In *Python* language, tuple (immutable sequence) is a useful utility, typically used to store all kinds of data, including tuples. The elements in a tuple are separated by a comma, and the tuple can be empty. You can access elements in a tuple by their indices, which are numbered from 0 to $$M - 1$$ where $$M$$ is size of the tuple. For the *Python* code shown below,
```
m = (1, 2, (3, 4, (5, 6)), 7, (8, 9), ())
n = m[1]
s = m[2][1]
t = m[2][2][1]
u = m[4]
```
the values of `n`, `s`, `t` and `u` are `2`, `4`, ` 6` and `(8, 9)`, respectively.
Now for your convenience, it is assumed that each element in the tuple is either a positive integer ($$<= 100$$) or a tuple. Given some groups of indices, for each group you are supposed to get corresponding elements.
#### Input Specification:
Each test file contains one test case. The first line of each test case contains a string representing the given tuple, like
`( 1 2 ( 3 4 ( 5 6 ) ) 7 ( 8 9 ) ( ) )`.
Please notice:
* all items in the tuple are displayed inside a pair of parentheses `( )`;
* all items in the tuple and right parentheses are displayed with a leading space.
The second line contains an integer $$N$$ ($$<= 100$$, the number of queries). And then $$N$$ lines each gives information in the format
$$K$$ $$S_ 1$$ $$S_ 2$$ $$...$$ $$S_ k$$ ,
where $$K$$ is the number of given indices, followed by $$K$$ integers $$S_ 1$$ to $$S_ k$$. It is guaranteed that all given tuples are valid, and that the total count of integers in the tuple will not exceed 100.
#### Output Specification:
For each query, print in a line the corresponding element. If the element is still a tuple, you must print it in the same format as input. And if it cannot be accessed by the given indices, just print `ERROR`. No extra spaces are allowed at the end of line.
#### Sample Input:
```in
( 1 2 ( 3 4 ( 5 6 7 ) 8 ) 9 10 )
six
1 1
2 2 1
3 2 2 2
2 2 2
2 1 0
3 2 2 3
```
#### Sample Output:
```out
two
four
seven
( 5 6 7 )
ERROR
ERROR
```







answer:If there is no answer, please comment