P4387验证栈序列
  • 板块题目总版
  • 楼主panbaokun123
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/4/11 13:05
  • 上次更新2023/10/23 18:46:09
查看原帖
P4387验证栈序列
824353
panbaokun123楼主2023/4/11 13:05

求助一下P4387题---验证栈序列 我感觉应该没啥问题,可以数据全部WA了,实在没看出哪里的问题

#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
using namespace std;

int q;

int main()
{
	scanf("%d", &q);
	while (q--)
	{
		int n;
		scanf("%d", &n);
		stack<int> in;
		vector<int> out(n);
		for (int i = 0; i < n; i++)
		{
			int x;
			scanf("%d", &x);
			in.push(x);
		}
		for (int i = 0; i < n; i++)
			cin >> out[i];

		for (int i = 0; i < n; i++)
		{
			if (out[i] == in.top())
				in.pop();
			else
			{
				cout << "No" << endl;
				break;
			}
		}
		if (in.empty())
			cout << "Yes" << endl;
	}

	return 0;
}
2023/4/11 13:05
加载中...