玄关!各位大佬帮忙看一下代码

P1042 [NOIP2003 普及组] 乒乓球

jingwenhan @ 2024-08-14 13:45:10

#include<bits/stdc++.h>
#define ll long long
using namespace std;
char c;
string b;
int ent1=0,ent2=0,ent=1;
int main(){
    cin>>c;
    if(c=='E'){
        cout<<"0:0"<<endl<<endl<<"0:0";
        return 0;
    }
    while(c!='E'){
        b[ent]=c;
        ent++;
        cin>>c;
    }
//  cout<<b[ent-1];
    for(int i=1;i<=ent-1;i++){
        if(b[i]=='W'){
            ent1++;
            if(ent1==11&&ent1-ent2>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
        if(b[i]=='L'){
            ent2++;
            if(ent2==11&&ent2-ent1>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
    }
    cout<<ent1<<":"<<ent2<<endl;
    ent1=0;
    ent2=0;
    cout<<endl<<endl;
    for(int i=1;i<=ent-1;i++){
        if(b[i]=='W'){
            ent1++;
            if(ent1==21&&ent1-ent2>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
        if(b[i]=='L'){
            ent2++;
            if(ent2==21&&ent2-ent1>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
    }
    cout<<ent1<<":"<<ent2<<endl;
    return 0;
}

by 朱梓煊ZZX @ 2024-08-14 13:51:34

@jingwenhan **直到分差大于或者等于


by jingwenhan @ 2024-08-14 13:55:09

@朱梓煊ZZX,49、42、29、22行判了的


by 朱梓煊ZZX @ 2024-08-14 13:57:19

@jingwenhan 如果比分大于11或21,你就错了


by jingwenhan @ 2024-08-14 14:00:19

#include<bits/stdc++.h>
#define ll long long
using namespace std;
char c;
string b;
int ent1=0,ent2=0,ent=1;
int main(){
    cin>>c;
    if(c=='E'){
        cout<<"0:0"<<endl<<endl<<"0:0";
        return 0;
    }
    while(c!='E'){
        b[ent]=c;
        ent++;
        cin>>c;
    }
//  cout<<b[ent-1];
    for(int i=1;i<=ent-1;i++){
        if(b[i]=='W'){
            ent1++;
            if(ent1>=11&&ent1-ent2>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
        if(b[i]=='L'){
            ent2++;
            if(ent2>=11&&ent2-ent1>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
    }
    cout<<ent1<<":"<<ent2<<endl;
    ent1=0;
    ent2=0;
    cout<<endl<<endl;
    for(int i=1;i<=ent-1;i++){
        if(b[i]=='W'){
            ent1++;
            if(ent1>=21&&ent1-ent2>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
        if(b[i]=='L'){
            ent2++;
            if(ent2>=21&&ent2-ent1>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
    }
    cout<<ent1<<":"<<ent2<<endl;
    return 0;
}

@朱梓煊ZZX ,还是wa


by hanxiaofensheng @ 2024-08-14 14:05:34

看了你的头像,差点还以为你是吉祥物呢


by hanxiaofensheng @ 2024-08-14 14:07:14

你是真不去看体检呀,题解的第2个人的代码写得还挺简单的。


by hanxiaofensheng @ 2024-08-14 14:07:58

去看题解


by 敢问高姓大名 @ 2024-08-14 14:13:40

@jingwenhan

string空空的直接越界访问更改会出乱码的,建议用char数组


by 敢问高姓大名 @ 2024-08-14 14:16:28

@jingwenhan

调好了,语法问题

#include<bits/stdc++.h>
#define ll long long
using namespace std;
char c;
char b[10000005];//
int ent1,ent2,ent=1;
int main(){
    cin>>c;
    if(c=='E'){
        cout<<"0:0"<<endl<<endl<<"0:0";
        return 0;
    }
    while(c!='E'){
        b[ent]=c;
        ent++;
        cin>>c;
    }
//  cout<<b[ent-1];
    for(int i=1;i<=ent-1;i++){
        if(b[i]=='W'){
            ent1++;
            if(ent1>=11&&ent1-ent2>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
        if(b[i]=='L'){
            ent2++;
            if(ent2>=11&&ent2-ent1>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
    }
    cout<<ent1<<":"<<ent2<<endl;
    ent1=0;
    ent2=0;
    cout<<endl; //换行一个就够了 
    for(int i=1;i<=ent-1;i++){
        if(b[i]=='W'){
            ent1++;
            if(ent1>=21&&ent1-ent2>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
        if(b[i]=='L'){
            ent2++;
            if(ent2>=21&&ent2-ent1>=2){
                cout<<ent1<<":"<<ent2<<endl;
                ent1=0; ent2=0;
            }
        }
    }
    cout<<ent1<<":"<<ent2<<endl;
    return 0;
}

|