怒写75行代码,换来46分……
#include<bits/stdc++.h>
using namespace std;
struct apploop{
string name;
string x,y;
};
stack<apploop> stk;
string names[111];
int t,l,w=-100,mw=0,ind=1;
string xmo,all,lex;
int strnCmp(string a,string b){
if(a.length()<b.length()) return -1;
else if(a.length()>b.length()) return 1;
else{
for(int i=0;i<a.length();i++){
if(a[i]<b[i]) return -1;
else if(a[i]>b[i]) return 1;
}
return 0;
}
}
int main(){
cin>>t;
while(t--){
all=""; lex="";
for(int i=0;i<111;i++) names[i]="";
ind=1; w=-100; mw=0;
while(!stk.empty()) stk.pop();
apploop appl;
cin>>l>>xmo;
int lt=l;
while(l--){
char tmp; cin>>tmp;
if(tmp=='F'){
cin>>appl.name>>appl.x>>appl.y;
int i=1;
for(;i<ind;i++){
if(names[i]==appl.name) break;
}
if(i!=ind&&l+1!=lt) all="ERR";
else{
stk.push(appl);
if(appl.y=="n") mw++;
else if(strnCmp(appl.x,appl.y)==1||appl.x=="n") mw--;
names[ind++]=appl.name;
}
}else if(tmp=='E'){
if(!stk.empty()){stk.pop(); mw--; ind--;}
else{
all="ERR";
break;
}
}
if(mw>w) w=mw;
}
if(!stk.empty()) all="ERR";
else if(all!="ERR"){
if(w==0) lex="O(1)";
else{
lex="O(n^";
lex+=(w+'0');
lex+=')';
}
if(lex==xmo) all="Yes";
else all="No";
}
cout<<all<<endl;
}
return 0;
}
救救本蒟!