Algorithm/lanqiao/series13sheng/tf_ac.py

34 lines
726 B
Python

import io
import sys
sys.stdin = io.StringIO('edda')
sys.stdin = io.StringIO('sdfhhhhcvhhxcxnnnnshh')
s_in = f"EMPTY{input()}"
while True:
flag = True
del_index = set()
for i in range(5, len(s_in) - 1):
if s_in[i - 1] == s_in[i] and s_in[i] != s_in[i + 1]:
del_index.add(i)
del_index.add(i + 1)
elif s_in[i - 1] != s_in[i] and s_in[i] == s_in[i + 1]:
del_index.add(i - 1)
del_index.add(i)
if del_index:
flag = False
s = ''
for idx, ch in enumerate(s_in):
if idx in del_index:
continue
s += ch
s_in = s
if flag:
break
print(s_in if s_in == 'EMPTY' else s_in.replace('EMPTY', ''))