#abc350f. F - Transpose
F - Transpose
Score: points
问题陈述
给定一个字符串 ,由大写和小写英文字母以及 (
和 )
组成。
字符串 中的括号是正确匹配的。
重复以下操作,直到无法再进行更多操作:
- 首先,选择一对整数 ,满足以下所有条件:
-
(
-
)
- 字符 都是大写或小写英文字母。
- 设 。
- 这里, 表示通过切换字符串 中每个字符的大小写(大写转小写,反之亦然)得到的字符串。
- 然后,删除 中的第 个到第 个字符,并将 插入到删除发生的位置。
参考示例输入和输出以获得澄清。
可以证明,使用上述操作可以从字符串中移除所有的 (
和 )
,并且最终字符串与操作的执行方式和顺序无关。
确定最终字符串。
中的括号是正确匹配的意味着什么?首先,正确的括号序列定义如下:
-
一个正确的括号序列是一个满足以下条件之一的字符串:
-
它是一个空字符串。
-
存在一个正确的括号序列 ,该字符串由按顺序连接
(
, ,)
形成。 -
存在非空的正确括号序列 和 ,该字符串由按顺序连接 和 形成。
如果从 中提取的 (
和 )
(不改变顺序)形成一个正确的括号序列,则称 中的括号是正确匹配的。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a string consisting of uppercase and lowercase English letters, (
, and )
.
The parentheses in the string are properly matched.
Repeat the following operation until no more operations can be performed:
- First, select one pair of integers that satisfies all of the following conditions:
-
(
-
)
- Each of the characters is an uppercase or lowercase English letter.
- Let .
- Here, denotes the string obtained by toggling the case of each character in (uppercase to lowercase and vice versa).
- Then, delete the -th through -th characters of and insert at the position where the deletion occurred.
Refer to the sample inputs and outputs for clarification.
It can be proved that it is possible to remove all (
s and )
s from the string using the above operations, and the final string is independent of how and in what order the operations are performed.
Determine the final string.
What does it mean that the parentheses in are properly matched? First, a correct parenthesis sequence is defined as follows:
-
A correct parenthesis sequence is a string that satisfies one of the following conditions:
-
It is an empty string.
-
There exists a correct parenthesis sequence , and the string is formed by concatenating
(
, ,)
in this order. -
There exist non-empty correct parenthesis sequences and , and the string is formed by concatenating and in this order.
The parentheses in are properly matched if and only if the (
s and )
s extracted from without changing the order form a correct parenthesis sequence.
Constraints
- consists of uppercase and lowercase English letters,
(
, and)
. - The parentheses in are properly matched.
Input
The input is given from Standard Input in the following format:
Output
Print the final string.
Sample Input 1
((A)y)x
Sample Output 1
YAx
Let us perform the operations for ((A)y)x
.
- Choose and . The substring
(A)
is removed and replaced witha
.- After this operation,
(ay)x
.
- After this operation,
- Choose and . The substring
(ay)
is removed and replaced withYA
.- After this operation,
YAx
.
- After this operation,
After removing the parentheses, the string becomes YAx
, which should be printed.
Sample Input 2
((XYZ)n(X(y)Z))
Sample Output 2
XYZNXYZ
Let us perform the operations for ((XYZ)n(X(y)Z))
.
- Choose and . The substring
(y)
is removed and replaced withY
.- After this operation,
((XYZ)n(XYZ))
.
- After this operation,
- Choose and . The substring
(XYZ)
is removed and replaced withzyx
.- After this operation,
(zyxn(XYZ))
.
- After this operation,
- Choose and . The substring
(XYZ)
is removed and replaced withzyx
.- After this operation,
(zyxnzyx)
.
- After this operation,
- Choose and . The substring
(zyxnzyx)
is removed and replaced withXYZNXYZ
.- After this operation,
XYZNXYZ
.
- After this operation,
After removing the parentheses, the string becomes XYZNXYZ
, which should be printed.
Sample Input 3
(((()))(()))(())
Sample Output 3
The final outcome may be an empty string.
Sample Input 4
dF(qT(plC())NnnfR(GsdccC))PO()KjsiI((ysA)eWW)ve
Sample Output 4
dFGsdccCrFNNnplCtQPOKjsiIwwEysAve