卡在用例6,报出 segment fault with invalid memory。自己的编译器中运行也一直卡住,个人怀疑是输入缓冲区溢出,但是也不知道怎么解决以及怎么修改。求大神指点
#include<iostream>
#include<cstring>
using namespace std;
#define M 2510
int main(){
string s = "";
string res1[M];
string res2[M];
int l = 0, r = 0, N = 0, count1 = 0;
int L = 0, R = 0, count2 = 0;
while(1){
N = 0;
cin >> s;
// cout << s;
while(N < s.size()){
if(s[N] == 'W') {
l++;
L++;
}
if(s[N] == 'L') {
r++;
R++;
}
if( (l >= 11 || r >= 11) && abs(l - r) >= 2) {
res1[count1++] = to_string(l) + ":" + to_string(r);
l = 0;
r = 0;
}
if( (L >= 21 || R >= 21) && abs(L - R) >= 2) {
res2[count2++] = to_string(L) + ":" + to_string(R);
L = 0;
R = 0;
}
if(s[N] == 'E'){
res1[count1++] = to_string(l) + ":" + to_string(r);
res2[count2++] = to_string(L) + ":" + to_string(R);
// 打印数据
for(int i = 0; i < count1; i++){
cout << res1[i] << endl;
}
cout << endl;
for(int i = 0; i < count2; i++){
cout << res2[i] << endl;
}
return 0;
}
N++;
}
}
}