【悬赏5~10RMB】RE求调!!人已调疯

P1575 正误问题

```cpp #include <bits/stdc++.h> using namespace std; string s; int l; void kongge(){ int l=0; while(s[l] == ' ') {s.erase(l,1);l++;} int r=s.length(); for(int i=0;i<r;i++){ if(s[i] == ' '){ i++; while(s[i] == ' ' && i < r) {s.erase(i,1);i++;} } else if(s[i] != ' '){ while(s[i] != ' '&&i<r) i++; i--; } } return ; } bool check1(int i){ /*kongge(); int t=i; char c[10]=""; int cnt=0; i-=2; while(s[i] != ' '){c[cnt++]=s[i]; i--;} if(c == "or" || c == "and" || c == "not") return 0; char c1[10]=""; while(s[--t] == ' '); cnt=0; i=t; while(s[++i] != ' ')c1[++cnt]=s[i]; if(c1 == "or" || c1 == "and" || c1 == "not") return 0;*/ return 1; } bool check(int i){ kongge(); if(s[i+4]=='f'&&s[i+5]=='a'&&s[i-5]=='t'&&s[i-4]=='r') return 1; if(s[i+4]=='t'&&s[i+5]=='r'&&s[i-6]=='f'&&s[i-5]=='a') return 1; return 0; } bool check2(int i){ kongge(); if(s[i+3]=='f'&&s[i+4]=='a'&&s[i-5]=='t'&&s[i-4]=='r') return 1; if(s[i+3]=='t'&&s[i+4]=='r'&&s[i-6]=='f'&&s[i-5]=='a') return 1; return 0; } void solve(){ l=s.length(); kongge(); if(l <= 5){ kongge(); cout << s; exit(0); } if(s[0]=='a' || s[0]=='o' || s[l-1]=='d' || s[l-1]=='r' || s[l-1]=='t'){ cout << "error";exit(0); } for(int i=0;i<l;i++){ if((s[i]=='t'&&s[i+1]=='r')||(s[i]=='f'&&s[i+1]=='a')||(s[i]=='o'&&s[i+1]=='r')){ if(!check1(i)){ cout << "error"; exit(0); } } } return ; } int main(){ getline(cin,s); solve(); for(int i=0;i<l;i++){ if(s[i] == 'n' && s[i+1] == 'o'){ if(!check1(i)){ cout << "error"; return 0; } s.erase(i,3); i++; int t=1; while(s[i] == ' ') i++; while(s[i] == 'n' && s[i+1] == 'o'){ s.erase(i,3);t++; while(s[i] == ' ') i++; } if(t%2){ if(s[i] == 't' && s[i+1] == 'r'){ s.erase(i,4); string tmp=" false "; s.insert(i,tmp); } else{ s.erase(i,5); string tmp=" true "; s.insert(i,tmp); } } } } solve(); for(int i=0;i<l;i++){ kongge(); if(s[i] == 'a' && s[i+1] == 'n'){ if(!check1(i)){ //and两边出现not或or cout << "error"; return 0; } if(s[i+4]=='f'&&s[i+5]=='a'&&s[i-6]=='f'&&s[i-5]=='a'){ //双false s.erase(i,9); } else if(s[i+4]=='t'&&s[i+5]=='r'&&s[i-5]=='t'&&s[i-4]=='r'){ //双true s.erase(i,8); } else if(check(i)){ //一true一false if(s[i+4]=='f') s.erase(i-5,8); else s.erase(i,8); } } } solve(); for(int i=0;i<l;i++){ kongge(); if(s[i] == 'o' && s[i+1] == 'r'){ if(!check1(i)){ cout << "error"; return 0; } if(s[i+3]=='f'&&s[i+4]=='a'&&s[i-6]=='f'&&s[i-5]=='a'){ //双false s.erase(i,8); } else if(s[i+3]=='t'&&s[i+4]=='r'&&s[i-5]=='t'&&s[i-4]=='r'){ //双true s.erase(i,7); } else if(check2(i)){ //一true一false if(s[i+3]=='f') s.erase(i,8); else s.erase(i-6,9); } } } solve(); cout << s; return 0; }
by Cstdio_Rabbit @ 2022-08-16 14:21:06


@[Queue_Hao](/user/486799) 你能解释一下check1吗(已解决RE,但会WA)
by Cstdio_Rabbit @ 2022-08-16 14:21:43


@[Queue_Hao](/user/486799) 实在太长了(
by Cstdio_Rabbit @ 2022-08-16 14:22:16


@[zswmb](/user/235901) 您能先说一下怎样解决RE吗? 是把check1函数注释掉就可以了吗?
by BlackPanda @ 2022-08-16 14:38:04


@[Queue_Hao](/user/486799) emmm我看看(改了一堆,你可以看我提交记录。)
by Cstdio_Rabbit @ 2022-08-16 14:38:55


```cpp void kongge(){ int l=0; while(s[l] == ' ') {s.erase(l,1);l++;} int r=s.length(); for(int i=0;i<r;i++){ if(s[i] == ' '){ i++; while(s[i] == ' ' && i < r) {s.erase(i,1);i++;} } else if(s[i] != ' '){ while(s[i] != ' '&&i<r) i++; i--; } } return ; }
by Cstdio_Rabbit @ 2022-08-16 14:39:17


```cpp void kongge(){ int l=0; while(s[l] == ' ') {s.erase(l,1);l++;}//l++ int r=s.length(); for(int i=0;i<r;i++){ if(s[i] == ' '){ i++; while(s[i] == ' ' && i < r) {s.erase(i,1);i++;}//i++ } else if(s[i] != ' '){ while(s[i] != ' '&&i<r) i++;//&&i<r i--; } } return ; }
by Cstdio_Rabbit @ 2022-08-16 14:40:05


@[zswmb](/user/235901) 这样改了就去不掉多余空格了,删除字符之后下标不需要+1吧
by BlackPanda @ 2022-08-16 14:44:56


删除之后,字符串后半段会自动前移吧
by BlackPanda @ 2022-08-16 14:45:37


@[Queue_Hao](/user/486799) 那就会陷入死循环吧
by Cstdio_Rabbit @ 2022-08-16 14:45:53


| 下一页