321
社区成员




已知字符串str。字符串str包含字符’x’,’y’。 如果相邻的两个字符不同,消除两个字符,优先从左边进行消除。 xyyx - > yx ->
目前为止,没有发现其他小伙伴用正则完成这个题目。。。
import re
s = input()
while re.search(r'(.)(?!\1).',s):
s = re.sub(r'(.)(?!\1).','',s)
print(s)
js 来一版
s = readline()
x = s.split('x').length - 1,n = s.length
print(2 * x == n ? '' : (2 * x > n ? 'x'.repeat(2 * x - n) : 'y'.repeat(n - 2 * x)))
来个不用正则的,因为只有两个字符 xy,所以统计下数量就可以计算出结果了
s = input().strip()
x,n = s.count('x'),len(s)
print('' if n == x * 2 else ('x' * (x * 2 - n) if x * 2 > n else 'y' * (n - x * 2)))