无语凝噎
查看原帖
无语凝噎
1519199
wang522024320147楼主2024/10/18 01:45
//
// Created by Admin on 2024/10/17.
// 乒乓球

#include <iostream>
#include <vector>

int main(){
    int win11 = 0, lose11 = 0, win21 = 0, lose21 = 0;
    std::vector<std::pair<int, int>> use11;
    std::vector<std::pair<int, int>> use21;
    std::string str, add;
    while(std::cin >> add){
        str += add;
    }
    for(auto &c : str){
        if(c == 'W'){
            ++win11;
            ++win21;
        }else if(c == 'L'){
            ++lose11;
            ++lose21;
        }else{
            //残局记录  换行读取
            use11.emplace_back(win11, lose11);
            use21.emplace_back(win21, lose21);
            break;
        }
        if(std::abs(win11 - lose11) >= 2 && (win11 >= 11 || lose11 >=11)){
            //11分制该局比赛结束
            use11.emplace_back(win11, lose11);
            win11 = 0;
            lose11 = 0;
        }
        if(std::abs(win21 - lose21) >= 2 && (win21 >=21 || lose21 >= 21)){
            //21分制该局比赛结束
            use21.emplace_back(win21, lose21);
            win21 = 0;
            lose21 = 0;
        }
    }
    for(auto &res : use11){
        std::cout << res.first << ':' << res.second << std::endl;
    }
    std::cout << std::endl;
    for(auto &res : use21){
        std::cout << res.first << ':' << res.second << std::endl;
    }
    return 0;
}

在本地运行一直while阻塞 浪费一堆时间...

2024/10/18 01:45
加载中...