実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 425 点
問題文
A
, B
, C
の 3 種類の文字のみからなる文字列 S が与えられます。
S が連続な部分文字列として文字列 ABC
を含む限り、下記の操作を繰り返します。
S に連続な部分文字列として含まれる文字列
ABC
のうち、S の中で最も左にあるものを、S から削除する。
上記の手順を行った後の、最終的な S を出力してください。
制約
- S は
A
,B
,C
のみからなる長さ 1 以上 2\times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
BAABCBCCABCAC
出力例 1
BCAC
与えられた文字列 S = BAABCBCCABCAC
に対して、下記の通りに操作が行われます。
- 1 回目の操作で、S =
BAABCBCCABCAC
の 3 文字目から 5 文字目のABC
が削除され、その結果 S =BABCCABCAC
となります。 - 2 回目の操作で、S =
BABCCABCAC
の 2 文字目から 4 文字目のABC
が削除され、その結果 S =BCABCAC
となります。 - 3 回目の操作で、S =
BCABCAC
の 3 文字目から 5 文字目のABC
が削除され、その結果 S =BCAC
となります。
よって、最終的な S は BCAC
です。
入力例 2
ABCABC
出力例 2
この入力例では、最終的な S は空文字列です。
入力例 3
AAABCABCABCAABCABCBBBAABCBCCCAAABCBCBCC
出力例 3
AAABBBCCC
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