String Concatenation
InterviewTime limit2sMemory limit256 MB
Given a string of lowercase letters and parentheses, where parentheses reverse the enclosed segment, output the resulting concatenated string.
- Level
Medium4 of 10
- Topics
- Stack, String, Implementation
- Solved
- No attempts yet
Problem
Many applied problems require various operations on strings. Two operations that occur often are reversing a string and concatenating two or more strings.
Reversing a string s yields the string sR, which consists of the same characters as s but in reverse order. For example, reversing "abcde" yields "edcba". In this problem, instead of sR the notation (s) is used.
Concatenating two strings s and t yields the string st, in which the characters of s come first, followed by the characters of t. Concatenation of three, four, or more strings is defined the same way. For example, concatenating "abc" and "cda" yields "abccda".
Your task is to find the result of concatenating several strings, some of which must be reversed.
Input
The input is a single line containing only lowercase Latin letters and parentheses. Its length does not exceed 200 characters. This line describes the concatenation of several strings, some of which must be reversed.
In the given string, every opening parenthesis has a closing parenthesis to its right, and every closing parenthesis has an opening parenthesis to its left. Between matched opening and closing parentheses there are no other parentheses, and there is always at least one letter.
Output
Output the result of the concatenation.