zoukankan      html  css  js  c++  java
  • 模拟、字符串--P1042 乒乓球 题解

    P1042 乒乓球
    字符串string的基本使用

    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <vector>
    #include <ctime>
    
    using namespace std;
    static const auto y = []() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        return 0;
    }();
    
    void pro1();
    int main() {
        pro1();
        return 0;
    }
    void pro1() {
        string str;
        vector<string> strs;
        strs.reserve(2500);
        while (true){
            getline(cin, str);
            if(str.length()==0)break;
            strs.push_back(str);
        }
        int role1=0,role2=0;
        bool flag = true;
        for (int i = 0; i < strs.size(); ++i) {
            for (int j = 0; j < strs[i].size(); ++j) {
                if(strs[i][j]=='E'){
                    cout<<role1<<":"<<role2;
                    role1=0,role2=0;
                    flag = false;
                    break;
                }
                strs[i][j]=='W'?role1+=1:NULL;
                strs[i][j]=='L'?role2+=1:NULL;
                if((role1>=11||role2>=11) && abs(role1-role2) >= 2){
                    cout<<role1<<":"<<role2<<endl;
                    role1=0,role2=0;
                }
            }
            if(!flag)break;
        }
        flag = true;
        cout<<endl;
        cout<<endl;
        for (int i = 0; i < strs.size(); ++i) {
            for (int j = 0; j < strs[i].size(); ++j) {
                if(strs[i][j]=='E'){
                    cout<<role1<<":"<<role2;
                    role1=0,role2=0;
                    flag = false;
                    break;
                }
                strs[i][j]=='W'?role1+=1:NULL;
                strs[i][j]=='L'?role2+=1:NULL;
                if((role1>=21||role2>=21) && abs(role1-role2) >= 2){
                    cout<<role1<<":"<<role2<<endl;
                    role1=0,role2=0;
                }
            }
            if(!flag)break;
        }
    
    }
    
    
  • 相关阅读:
    linux 硬件信息
    docker note
    Shell cmd set note
    mysql management note
    scp noneed passwd
    update kernel
    数据包处理过程
    tcp/ip分片
    sockopt note
    Python note
  • 原文地址:https://www.cnblogs.com/sunqiangstyle/p/10312330.html
Copyright © 2011-2022 走看看