终于跨过这个坑,没啥好说的,只是纪念一下
#include<bits/stdc++.h> using namespace std; bool xSy(string s); int main(){ int t, l, w, max; bool flag; string giveCplx, realCplx, temp2, temp3; stack<string> s; vector<char> values; char temp[100]; cin >> t; while(t--){ cin >> l >> giveCplx; getchar(); w = 0; max = 0; flag = true; values.clear(); realCplx = ""; temp2 = temp3 = ""; while(!s.empty()) s.pop(); while(l--){ gets(temp); // cout << temp << endl; if(temp[0] == ‘F‘){ if(w != 0){ w += s.size(); if(w > max) max = w; w = 0; } s.push(temp); values.clear(); }else if(temp[0] == ‘E‘){ if(s.empty()){ flag = false; } else{ temp2 = s.top(); s.pop(); } if( find(values.begin(), values.end(), temp2[2]) != values.end() ){ flag = false; // cout << temp2[5] << endl; }else{ if( xSy(temp2) ){ if( temp2[temp2.size()-1] == ‘n‘ && temp2[4] != ‘n‘ ) w++; values.push_back(temp2[2]); }else{ // values.clear(); w = 0; } } } } if(w > max) max = w; if(!s.empty()) flag = false; if(flag){ if(max == 0){ realCplx += "O(1)"; }else{ realCplx += "O(n^"; while(max != 0){ temp3 += max%10 + ‘0‘; max /= 10; } for(int i=temp3.size()-1; i>=0; i--) realCplx += temp3[i]; realCplx += ")"; } // cout << realCplx << endl; if(realCplx == giveCplx) cout << "Yes" << endl; else cout << "No" << endl; }else{ cout << "ERR" << endl; } } return 0; } bool xSy(string s){ int i, j; int a, b, c; a = b = 0; c = 1; if(s[s.size()-1] == ‘n‘){ return true; }else{ for(i=s.size()-1; i>=0; i--){ if(s[i] == ‘ ‘) break; a += (s[i]-‘0‘) * c; c *= 10; } c = 1; for(j=i-1; j>=0; j--){ if(s[j] == ‘ ‘) break; if(s[j] == ‘n‘ && s[s.size()-1] != ‘n‘){ return false; } b += (s[j]-‘0‘) * c; c *= 10; } if( a < b ) return false; else return true; } }
原文:https://www.cnblogs.com/ssNiper/p/11208448.html