xiongty2024 @ 2023-10-04 19:47:05
#include<bits/stdc++.h>
using namespace std;
int T,n,tmp,f;
stack <int> st;
int main()
{
int i,j;
scanf("%d",&T);
for(i=1;i<=T;i++)
{
f=0;
scanf("%d",&n);
for(j=1;j<=n;j++)
{
scanf("%d",&tmp);
st.push(tmp);
}
for(j=1;j<=n;j++)
{
scanf("%d",&tmp);
if(st.top()==tmp)
st.pop();
else
{
f=1;
break;
}
}
if(f==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
by IceKylin @ 2023-10-04 20:54:57
@cwfxxty
#include<bits/stdc++.h>
using namespace std;
int T,n,tmp,f;
stack <int> st;
int a[100005],b[100005];
int main()
{
int i,j;
scanf("%d",&T);
for(i=1;i<=T;i++)
{
f=0;
scanf("%d",&n);
for(j=1;j<=n;j++)
{
scanf("%d",&a[j]);
}
for(j=1;j<=n;j++)
{
scanf("%d",&b[j]);
}
int hd=1;
for(j=1;j<=n;j++)
{
st.push(a[j]);
while(!st.empty()&&st.top()==b[hd]){
hd++;
st.pop();
}
}
if(st.empty())
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
while(!st.empty())st.pop();
}
return 0;
}
改了一下,过了