输入一个只包含英文字母的字符串,字符串中的两个字母如果相邻且相同,就可以消除。
在字符串上反复执行消除的动作,直到无法继续消除为止,此时游戏结束。
输出最终消除完后留下的字符串。
测试用例1:
输入aaaa
输出 空字符串
测试用例1:
输入abccbd
输出 ad
#消消乐 列表的pop方法
def f():
ls = input()
new_ls = []
for i in ls:
if new_ls and new_ls[-1] == i:
new_ls.pop()
else:
new_ls.append(i)
print(''.join(new_ls))
while True:
try:
f()
except:
break