python写的求调试,第一个和最后一个没过(会关)
查看原帖
python写的求调试,第一个和最后一个没过(会关)
1805464
Porphirin楼主2025/7/28 10:53

第一个和最后一个测试点是WA

import sys


def game(score, end):
    res = []
    w = 0
    l = 0
    for c in score:
        if c == 'W':
            w += 1
        elif c == 'L':
            l += 1
        else:
            continue

        if (w >= end or l >= end) and abs(w - l) >= 2:
            res.append(f"{w}:{l}")
            w = 0
            l = 0
    if w > 0 or l > 0:
        res.append(f"{w}:{l}")
    return res


def main():
    data = []
    for line in sys.stdin:
        line = line.strip()
        if not line:
            continue
        if 'E' in line:
            data.append(line[:line.index('E')])
            break
        data.append(line)
    scores = ''.join(data)

    res1 = game(scores, 11)
    res2 = game(scores, 21)

    print('\n'.join(res1))
    print()
    print('\n'.join(res2))

if __name__ == "__main__":
    main()
2025/7/28 10:53
加载中...