https://www.luogu.com.cn/paste/gxbmxx7v
题目
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
#define int long long
int a,n,m,b[N];
int Stk[N],top;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++){
cin >> a;
Stk[top++] = a;
}
for(int i = 1;i <= m;i++){
cin >> b[i];
}
for(int i = top;i >= 0;i--){
for(int j = 1;j <= m;j++){
if(Stk[i] == b[j]){
cout << Stk[i] << " ";
break;
}
}
}
return 0;
}
悬关