后面四个测试样例都WA了,求大佬找找错误
#include <bits/stdc++.h>
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
int maxW = 0;
stringstream ss;
void solution(int& cnt, int w, int &L, int &flag, stack<string> &IStack, map<string, int> &IMap, int flag2)
{
int currentW = w;
while (true)
{
w = currentW;
if (L == 0){
//g_cnt = cnt;
return;
}
string C;
cin >> C;
L--;
if (C == "F")
{
cnt ++;
string i, x, y;
cin >> i >> x >> y;
if (IMap.count(i) && IMap[i] != 0)
{
flag = 1;
return;
}
else
{
IStack.push(i);
IMap[i] = 1;
}
// 判断x,y大小关系
if (!flag2)
{
if (x == "n" && y != "n")
{
flag2 = 1;
}
else if (y == "n" && x != "n")
{
w ++;
maxW = max(maxW,w);
}
else if (y == "n" && x == "n")
{
}
else
{
int temp1,temp2;
ss << x;
ss >> temp1;
ss.clear();
ss << y;
ss >> temp2;
ss.clear();
if(x <= y){
}else
{
flag2 = 1;
}
}
}
solution(cnt, w, L, flag, IStack, IMap, flag2);
}
else
{
cnt--;
if (!IStack.empty())
{
string i = IStack.top();
IStack.pop();
IMap[i] = 0;
return;
}
else
{
flag = 1;
return;
}
if (cnt < 0)
{
flag = 1;
return;
}
return;
}
}
return;
}
// https://www.luogu.com.cn/problem/P3952
int main()
{
ios::sync_with_stdio(0); //解决c++输入输出流被卡问题
int t;
cin >> t;
while (t--)
{
int flag = 0;
int L;
string str;
cin >> L >> str;
int cnt = 0;
int w = 0;
string res;
stack<string> IStack;
map<string, int> IMap;
solution(cnt, w, L, flag, IStack, IMap, 0);
if (flag || cnt != 0)
{
cout << "ERR" << endl;
}
else
{
if (maxW == 0)
{
res = "O(1)";
}
else
{
ss << maxW;
string temp;
ss >> temp;
ss.clear();
res = "O(n^" + temp + ")";
}
if (res == str)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
maxW = 0;
}
system("pause");
return 0;
}