chacoderのブログ

競技プログラミングそのほか

set を使う

はじめに

C++STLのsetこれまであまり使ったことがありませんでしたが昨日のABC203Eで使われてるのを見て、なるほどこんなふうに使うんだと勉強になりました。

練習

#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