GOC11A - Appending String
You are given a string S, you need to build another string T by expanding S according to the steps below (traversing left to right):
If current character is an alphabet, append it to T.
If current character is a digit, suppose the digit is N, then do T = N*T. Here N*T means appending T N times. See sample for better understanding.
Go to next character if exists then restart from step 1.
Upon expanding S, you will be given Q queries. For each query you have to print the ith character of the string T.
Hint : After expanding the string S=”a3b2c1” T will be = “aaabaaabc”
The first line will be the test case number(t<=10).
In the first line of each test you will be given a string consisting of lowercase letters and digits. And it is guaranteed that length of T will be no more than 1000.
Next line will contain an integer Q(<=100000) denoting total numbers of queries. Following Q lines each contains an integer X.
Looked like potentially a WA-nightmare, yet AC at first attempt. No zero's in S, also X is 1-indexed. Nice problem.
By 'length of T will be no more than 1000' it means the length of the actual string T being built from the input string, NOT the input string. Not only the final length will be small, but also 'intermediate' (while building).
easy one ..
The digit in the string can be 0 too.! Costed me 2 WA
dont forget -1 if not in range cost me 1 wa
Output -1 when x>length of t, costed me a WA! Easy one!!
What's the range of X?
Last edit: 2016-09-01 14:57:29
finally ac :)
Can anyone give tricky testcases?