Question: Please write the code in C language Exercise 2.22 String Decoder This problem asks you to write a decoder to read an input string and
Please write the code in C language
Exercise 2.22 String Decoder This problem asks you to write a decoder to read an input string and decode it into another string. If the decoder observes a pattern " n (characters)" in the input string, the characters inside the bracket will be repeated for n times. Otherwise, the decoder simply outputs the characters without any modifications. For example, if the input is "3(ab)cd", the output will be "abababcd". For your conveniences, you can assume the followings hold true for all input string. 1. The input string only contains alphabetic characters, digits from ' 0 ' to ' 9 ', and brackets. 2. The brackets are always valid. Hence, we will not have input like "10(a", or "20(a))". 3. There must be at least one digit before a pair of brackets. Hence, we will not have input like "ab(10)", or "(100)". 4. A pair of brackets contains at least one alphabetic character. Hence, we will not have input like "5()", or "5(6)". 5. The right neighbor of a digit will not be an alphabetic character. Hence, we will not have input like " 10a ", "ab2c", or " 2a(10)" 6. A digit will not locate at the end of the string. Hence, we will not have input like "a10", "2(cd)10", or "3" Input There are several test cases in the input. The first line is an integer t100000, which indicates the number of test cases. For each test case, there is one line containing a string. The length of the string is between 1 and 10000 , inclusive. Output For each test case, output one line containing the decoded string. Sample Input 3 2(a)3(bc) 3(c5(d)) 2( irwin)3(king) prof Sample Output aabcbcbc cdddddcdddddcddddd irwinirwinkingkingkingprof 59
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
