시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 256 MB | 0 | 0 | 0 | 0.000% |
The Pact system enables programmers to encode arbitrary data structures built of records, arrays, strings and integers. An encoded structure takes the form of a string of printable characters. It can be written to a file, or transmitted over a network. Pact is designed to be hardware, operating system and programming language independent. Encoding software has been built. Your task is to build and test a decoder.
Records in Pact are sets of named components. Two records in Pact have the same type if they have components of the same types with the same names. A record must have at least one component. Arrays are one dimensional, indexed from 0, and all elements of an array must be of the same type. Arrays must have at least one element. Two arrays are of the same type if their elements are of the same type. Note: two arrays with the same element type, but different lengths, are considered to be of the same type.
In Pact, data is basically encoded as follows (see sample data for examples):
12
is encoded as 12
123456543254321
is encoded as 123456543254321
-23
is encoded as -23
Hello
is encoded as "Hello"
Say "Hello"
is encoded as "Say \"Hello\""
"\"Hello\""
is encoded as "\"\\\"Hello\\\"\""
[5,7,4,3]
is encoded as ;5,7,4,3;
[red,green,blue]
is encoded as ;"red","green","blue";
[[1,2,3],[4,5,6],[7,8]]
is encoded as ;;1,2,3;,;4,5,6;,;7,8;;
(x:5,y:7,n5:Fred)
is encoded as ;x:5,y:7,n5:"Fred";
This basic encoding is modified by a compression feature in Pact that works as follows.
[5,5,5,7,6,6]
is encoded as ;5*3,7,6*2;
[(x:5,y:6),(x:5,y:6)]
is encoded as ;;x:5,y:6;*2;
[(x:5,y:6),(x:5,y:7)]
is encoded as ;;x:7,y:6;,;y:7;;
[(x:5,y:6),(x:5,y:6)]
is encoded as ;;x:5,y:6;*2;
[(a:5,b:(x:6,y:7)),(a:5,b:(x:6,y:8))
is encoded as ;;a:5,b:;x:6,y:7;;,;b:;x:6,y:8;;;
Input consists of a sequence of problems. Each problem starts with a line with a positive integer N. This is followed by a line with a Pact encoded string of length no greater than 1,000 characters. There are then N lines, each with a test. Tests are data accesses – a ‘v’ character followed by zero or more indices or field selectors. For example:
v v[0].x v.x.name v.x.arr[5].str
Index values are always integer literals i: 0<=i<=100. Test data accesses always reach strings or integers – they never refer to entire arrays or records. You may assume that test data accesses always correctly match the structure encoded. You may also assume that the total number of string and integer values in a data structure is no greater than 1000. End of input is signalled by an N value of zero.
For each problem, output a line with the text “Problem n” where n is the problem number 1, 2, … This should be followed by N lines giving the string or integer accessed by the test.
1 "Say \"Hello\"" v 3 ;"red","green","blue"; v[0] v[1] v[2] 4 ;;x:5,y:6;*2; v[0].x v[0].y v[1].x v[1].y 0
Problem 1 Say "Hello" Problem 2 red green blue Problem 3 5 6 5 6