50分萌新,求分析问题
查看原帖
50分萌新,求分析问题
323411
sakura1楼主2021/6/8 20:19
#include<iostream>
using namespace std;


void inputIn(char *score ,int &number);//输入数据
void caculate(char *score,int number);//分析数据
//void outIn(char *score,int &number);
int main(){
    char score[62500];//比赛得分记录字符数组
    int number;//对局数
    inputIn(score,number);
    caculate(score,number);
    //outIn(score,number);
    return 0;
}

//输入数据
void inputIn(char *score,int &number){
    int i=0;
    char c;
    cin>>c;
    while(c!='E'){
        score[i]=c;
        i++;
        cin>>c;
    }
    number=i;
}
/*
void outIn(char *score,int &number){
    for(int i=0;i<number;i++){
        cout<<score[i];
    }
}
*/

//分析数据
void caculate(char *score,int number){
    //*********************11赛制*********************
    int playerW=0;//运动员甲得分
    int playerL=0;//运动员乙得分
    for(int i=0;i<number;i++){
        if(score[i]=='W'){
                playerW++;
                if(playerW>=11&&playerW-playerL>=2){//分数大于等于11且分差为2时结束
                    cout<<playerW<<':'<<playerL<<endl;
                    playerW=0;
                    playerL=0;
                }
        }
        else if(score[i]=='L'){
            playerL++;
            if(playerL>=11&&playerL-playerW>=2){
                cout<<playerW<<':'<<playerL<<endl;
                playerW=0;
                playerL=0;
            }
        }
    }
    if(playerW!=0&&playerL!=0){//未结束的对局输出
        cout<<playerW<<':'<<playerL<<endl;
    }
    cout<<endl;
    //***********************21赛制************************
    playerW=0;
    playerL=0;
    for(int i=0;i<number;i++){
        if(score[i]=='W'){
                playerW++;
                if(playerW>=21&&playerW-playerL>=2){
                    cout<<playerW<<':'<<playerL<<endl;
                    playerW=0;
                    playerL=0;
                }
        }
        else if(score[i]=='L'){
            playerL++;
            if(playerL>=21&&playerL-playerW>=2){
                cout<<playerW<<':'<<playerL<<endl;
                playerW=0;
                playerL=0;
            }
        }
    }
    if(playerW!=0&&playerL!=0){
        cout<<playerW<<':'<<playerL<<endl;
    }
}

2021/6/8 20:19
加载中...