求助各位大佬
查看原帖
求助各位大佬
241986
LiuHao2019楼主2020/5/4 09:11

题目传送门

这道题用样例应该是输出

Yes

No


但实际输出

No

No


找了半天不知道怎么错的

附上代码:

#include<stdio.h>
#include<stack>
using namespace std;
stack<int> a;
int tmp;
int w;
int main(){
	int q,n;
	scanf("%d",&q);
	bool x[q+1];
	for(int i = 1;i <= q;i ++){
		x[i] = true;
		scanf("%d",&n);
		for(int i = 1;i <= n;i ++){
			scanf("%d",&w);
			a.push(w);
		}
		for(int i = 1;i <= n;i ++){
			scanf("%d",&tmp);
			if(tmp == a.top()){
				a.pop();
			}
			else{
				x[i] = false;
				break;
			}
		}
		if(a.empty() != true) x[i] = false;
	}
	for(int i = 1;i <= q;i ++)
		if(x[i] == true) printf("Yes\n");
		else printf("No\n");
}
2020/5/4 09:11
加载中...