帮我修改上面的代码,要求输入输出格式如下,输入: WWWWWWWWWWWWWWWWWWWWWWLW 输出: 11:0 11:0 1:1 21:0 2:1
时间: 2024-01-09 21:04:25 浏览: 95
好的,根据您的要求,以下是修改后的代码:
```python
while True:
# 读入输入,直到遇到 E 结束
data = input().strip()
if data == 'E':
break
# 去除空格
data = data.replace(' ', '')
# 初始化比分和局数
score11 = [0, 0]
score21 = [0, 0]
game11 = [0, 0]
game21 = [0, 0]
current_score11 = [0, 0]
current_score21 = [0, 0]
current_game11 = [0, 0]
current_game21 = [0, 0]
# 处理比赛记录
for i in range(len(data)):
if data[i] == 'W':
current_score11[0] += 1
current_score21[0] += 1
else:
current_score11[1] += 1
current_score21[1] += 1
# 判断比分是否达到 11 或 21 分
if current_score11[0] == 11 or current_score11[1] == 11:
# 判断哪个人赢了这局
winner = 0 if current_score11[0] == 11 else 1
score11[winner] += 1
current_score11 = [0, 0]
game11[winner] += 1
elif current_score21[0] == 21 or current_score21[1] == 21:
winner = 0 if current_score21[0] == 21 else 1
score21[winner] += 1
current_score21 = [0, 0]
game21[winner] += 1
# 判断是否需要进入加赛
if abs(current_score11[0] - current_score11[1]) >= 2 and sum(current_score11) >= 20:
winner = 0 if current_score11[0] > current_score11[1] else 1
score11[winner] += 1
current_score11 = [0, 0]
game11[winner] += 1
elif abs(current_score21[0] - current_score21[1]) >= 2 and sum(current_score21) >= 40:
winner = 0 if current_score21[0] > current_score21[1] else 1
score21[winner] += 1
current_score21 = [0, 0]
game21[winner] += 1
# 输出比分
print('%d:%d' % (score11[0], score11[1]), end=' ')
print('%d:%d' % (game11[0], game11[1]), end=' ')
print('%d:%d' % (score21[0], score21[1]), end=' ')
print('%d:%d' % (game21[0], game21[1]))
```
这个程序的修改主要是在输出格式上,每一行输出四个数,中间用空格分隔。其中前两个数表示 11 分制下的比分,第三、四个数表示 21 分制下的比分。每一行的四个数之间没有空格,行末没有多余的空格或换行符。
阅读全文