返回顶部

Write and Erase

\(1≤N≤100000\),$1≤Ai≤1000000000(=10^9) $$1≤Ai≤1000000000(=10^
9)$

这么大不能用数组存,用STLset集合!

#include <bits/stdc++.h>
#include <set>
using namespace std;
set<int> a;
int main()
{
    int n;
    cin >> n;
    while (n--){
        int x;
        cin>>x;
        if(a.find(x) != a.end())
            a.erase(x);
        else 
            a.insert(x);
    }
    cout<<a.size();
    // system("pause");
    return 0;
}

a.find(x) 是在集合中寻找x这个元素,对比a的先前最后一个元素。这个过程可以画图理解。

posted @ 2022-01-20 22:17  zrc4889  阅读(29)  评论(0编辑  收藏  举报