Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
494 B
2
Indexable
Never
def reverse_in_parentheses(s):
    stack = []
    result = []

    for char in s:
        if char == '(':
            stack.append(result)
            result = []
        elif char == ')':
            inner = result
            result = stack.pop()
            result.extend(inner[::-1])
        else:
            result.append(char)

    return ''.join(result)


input_str = input("Введите строку: ")
result = reverse_in_parentheses(input_str)
print("Результат:", result)