set を使う
練習
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) #define int long long signed main(){ set<int>s; int temp; int n; cin>>n; rep(i,n){ cin>>temp; s.insert(temp); } int m; cin>>m; rep(i,m){ cin>>temp; s.erase(temp); } for(auto e:s){ cout<<e<<endl; } return 0; }
入力例
5 2 4 8 10 101 3 1 2 4
出力例
8 10 101