求助,为什么换一种读入方式就无法读入字符
查看原帖
求助,为什么换一种读入方式就无法读入字符
534582
lin_ac楼主2021/11/15 14:05
#include<bits/stdc++.h>
using namespace std;

char str[100000];
int f[10]={11,21};
int main(){
    int cnt=0;
    char cmp;
    while (1)
    {
        cin>>cmp;
        if(cmp=='E') break;
        str[cnt]=cmp;
        cnt++;
    }
    /*
    for(int i=1;;i++){      //这样输入就无法向数组里面读入字符
        cin>>str[i];
        if(str[i]=='E') break;
    }
    */
    for(int x=0;x<2;x++){
        int a=0,b=0;
        for(int i=0;i<cnt;i++){
            if(str[i]=='W') a++;
            if(str[i]=='L') b++;
            if(max(a,b)>=f[x]&&abs(a-b)>=2){
                cout<<a<<":"<<b<<endl;
                a=0,b=0;
            }
        }
        cout<<a<<":"<<b<<endl;
        if(x!=1) cout<<endl;
    }
    return 0;
}
  1. 一开始我是按照注释里面读入字符的,但是debug时候发现并没有读入,但是for循环确实也走了,看了题解之后发现用现在这种方法读入就能ac
2021/11/15 14:05
加载中...