|  | 
 
| 
s = input("请输入一个字符串:")
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  
 res = []
 for each in s:
 if res and res[-1].lower() == each.lower() and res[-1] != each:
 res.pop()
 else:
 res.append(each)
 
 for each in res:
 print(each, end='')
 
但是会添加元素进去啊 复制代码s = input("请输入一个字符串:")
res = []
for each in s:
    # 如果列表不为空,且each和res最后一个元素互为大小写,就把res最后一个元素删除,否则就把each添加进去
    # 注意,前提是res不为空,为空的话直接把each添加进去
    if res and res[-1].lower() == each.lower() and res[-1] != each:
        res.pop()
    else:
        # 进行追加元素操作
        res.append(each)
for each in res:
    print(each, end='')
 | 
 |