P1042 [NOIP2003 普及组] 乒乓球

// Problem: P1042 [NOIP2003 普及组] 乒乓球
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1042
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn

#include <bits/stdc++.h>

using namespace std;

void printRes(int n, string str) {
    int cntA = 0, cntB = 0;
    for(char c : str) {
        if (c == 'W') {
            ++cntA;
        } else {
            ++cntB;
        }
        // 一局结束
        // 某一个人的分值达到n,且两个人的分差大于或等于2
        if ((cntA >= n || cntB >= n) && abs(cntA - cntB) >= 2) {
            cout << cntA << ":" << cntB << endl;
            cntA = 0;
            cntB = 0;
        }
    }
    // 新的一轮开始,或者上一局没有打完
    cout << cntA << ":" << cntB << endl;
}

int main() {
    char c;
    string str;
    while (cin >> c && c != 'E') {
        str += c;
    }
    printRes(11, str);
    cout << endl;
    printRes(21, str);
    return 0;
}
posted @ 2021-12-27 11:20  Pannnn  阅读(274)  评论(0)    收藏  举报
-->