103283: [Atcoder]ABC328 D - Take ABC
Description
Score : $425$ points
Problem Statement
You are given a string $S$ consisting of three different characters: A
, B
, and C
.
As long as $S$ contains the string ABC
as a consecutive substring, repeat the following operation:
Remove the leftmost occurrence of the substring
ABC
from $S$.
Print the final string $S$ after performing the above procedure.
Constraints
- $S$ is a string of length between $1$ and $2 \times 10^5$, inclusive, consisting of the characters
A
,B
, andC
.
Input
The input is given from Standard Input in the following format:
$S$
Output
Print the answer.
Sample Input 1
BAABCBCCABCAC
Sample Output 1
BCAC
For the given string $S = $ BAABCBCCABCAC
, the operations are performed as follows.
- In the first operation, the
ABC
from the $3$-rd to the $5$-th character in $S = $BAABCBCCABCAC
is removed, resulting in $S = $BABCCABCAC
. - In the second operation, the
ABC
from the $2$-nd to the $4$-th character in $S = $BABCCABCAC
is removed, resulting in $S = $BCABCAC
. - In the third operation, the
ABC
from the $3$-rd to the $5$-th character in $S = $BCABCAC
is removed, resulting in $S = $BCAC
.
Therefore, the final $S$ is BCAC
.
Sample Input 2
ABCABC
Sample Output 2
In this example, the final $S$ is an empty string.
Sample Input 3
AAABCABCABCAABCABCBBBAABCBCCCAAABCBCBCC
Sample Output 3
AAABBBCCC
Output
问题描述
给你一个包含三个不同字符的字符串$S$:A
、B
和C
。
只要$S$包含连续子串ABC
,就执行以下操作:
从$S$中删除左most的子串
ABC
。
执行上述过程后,输出最终的字符串$S$。
约束
- $S$是一个长度在$1$到$2 \times 10^5$之间的字符串,包含字符
A
、B
和C
。
输入
输入通过标准输入给出,格式如下:
$S$
输出
输出答案。
样例输入1
BAABCBCCABCAC
样例输出1
BCAC
对于给定的字符串$S = $ BAABCBCCABCAC
,执行的操作如下。
- 在第一次操作中,从$S = $
BAABCBCCABCAC
的第$3$个到第$5$个字符中删除ABC
,得到$S = $BABCCABCAC
。 - 在第二次操作中,从$S = $
BABCCABCAC
的第$2$个到第$4$个字符中删除ABC
,得到$S = $BCABCAC
。 - 在第三次操作中,从$S = $
BCABCAC
的第$3$个到第$5$个字符中删除ABC
,得到$S = $BCAC
。
因此,最终的$S$为BCAC
。
样例输入2
ABCABC
样例输出2
在这个例子中,最终的$S$是一个空字符串。
样例输入3
AAABCABCABCAABCABCBBBAABCBCCCAAABCBCBCC
样例输出3
AAABBBCCC