【悬赏5~10RMB】RE求调!!人已调疯
查看原帖
【悬赏5~10RMB】RE求调!!人已调疯
486799
BlackPanda楼主2022/8/16 14:02

Q:为什么是5~10RMB?

A:看回答情况酌情给悬赏

#include <bits/stdc++.h>
using namespace std;
string s;
int l;
void kongge(){
	int l=0; 
	while(s[l] == ' ')	{s.erase(l,1);}
	int r=s.length();
	for(int i=0;i<r;i++){
		if(s[i] == ' '){
			i++;
			while(s[i] == ' ' && i < r)	{s.erase(i,1);}
		}
		else if(s[i] != ' '){
			while(s[i] != ' ') 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;
}
2022/8/16 14:02
加载中...