腾讯模拟笔试
#include <bits/stdc++.h> using namespace std; int main(){ int n; std::ios::sync_with_stdio(false); map<long long, int> temp; while (cin >> n) { int n2 = n; while (n--) { long long a; cin >> a; if (temp[a] == 0) { temp[a]=1; } else temp[a] = 0; } long long sum = 0; bool flag; if (n2 & 1) { flag = 1; for (auto i : temp) { if (i.second == 1) { if (flag) sum += i.first; else sum -= i.first; flag = !flag; } } } else { flag = 1; for (auto i : temp) { if (i.second == 1) { if (flag) sum -= i.first; else sum += i.first; flag = !flag; } } } cout << sum << endl; } return 0; }
#腾讯#