不知道怎么就RE了,请大佬看看吧!
#include <bits/stdc++.h>
using namespace std;
vector<string> delspace(vector<string> d){
vector<string> d1;
int sd = d.size();
for (int i=0;i<sd;i++){
if (d[i] != ""){
d1.push_back(d[i]);
}
}
return d1;
}
int main(){
bool flag = 0;
vector<string> bds,bds1;
string sbds,ss = "";
getline(cin,sbds);
//cout << sbds << endl;
for (int i=0;i<sbds.length();i++){
if (sbds[i] == ' '){
bds.push_back(ss);
ss = "";
} else if (i == sbds.length()-1){
ss+= sbds[i];
bds.push_back(ss);
ss = "";
} else {
ss += sbds[i];
}
// cout << ss << " ";
}
int sts = bds.size();
/*
for (int i=0;i<sts;i++){
cout << bds[i] << " ";
}
*/
if(bds[sts-1] == "not" || bds[sts-1] == "and" || bds[sts-1] == "or" || bds[0] == "and" || bds[0] == "or"){
cout << "error";
return 0;
}
bds.swap(bds1);
for (int i=sts-1;i>=0;i--){
if (bds1[i] == "not"){
if (bds1[i+1] == "true"){
bds1[i] = "false";
} else if (bds1[i+1] == "false"){
bds1[i] = "true";
} else {
cout << "error";
return 0;
}
bds1.erase(bds1.begin()+i);
}
}
for (int i=0;i<sts-1;i--){
if (bds1[i] == "and"){
if ((bds1[i-1] == "false") || (bds1[i+1] == "false")){
bds1[i] = "false";
} else if ((bds1[i-1] == "true") && (bds1[i+1] == "true")){
bds1[i] = "true";
} else {
cout << "error";
return 0;
}
bds1.erase(bds1.begin()+i);
bds.erase(bds1.begin()+i-1-1);
} else if(bds1[i] == "or") {
if ((bds1[i-1] == "true") || (bds1[i+1] == "true")){
bds1[i] = "true";
} else if (((bds1[i-1] == "false") && (bds1[i+1] == "false"))){
bds1[i] = "false";
} else {
cout << "error";
return 0;
}
bds1.erase(bds1.begin()+i);
bds.erase(bds1.begin()+i-1-1);
}
}
bds1.swap(bds);
for (int i=0;i<sts;i++){
cout << bds[i] << " ";
}
return 0;
}