为什么会有runtime error,还有不对的
查看原帖
为什么会有runtime error,还有不对的
1217129
data740楼主2024/9/10 21:15
#include<iostream>
#include<stack>
using namespace std;

stack<int>n;
int pushed[100005];
int poped[100005];

int main()
{
	int cnt;
	cin >> cnt;
	while (cnt--)
	{ 
		int i = 0, j = 0;
		int num;
		cin >> num;
		int tmp = num;
		while (num--)
		{
			cin >> pushed[i++];
		}
		num = tmp;
		while (num--)
		{
			cin >> poped[j++];
		}
		num = tmp;
		int now = 1;
		n.push(pushed[0]);
		for (int i = 0; i < num; i++)
		{
			while (poped[i] != n.top() && now < num)
			{
				n.push(pushed[now++]);
			}
			if (poped[i] == n.top())n.pop();
			else
			{
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
}

2024/9/10 21:15
加载中...