贴一个利用异或性质的代码

#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 110;

int n, w[N];
int s[N];

void solve() {
    memset(w, 0, sizeof w);
    memset(s, 0, sizeof s);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> w[i];

    for (int i = 1; i <= n; ++i) s[i] = s[i - 1] ^ w[i];

    for (int i = 1; i <= n; ++i) {
        int other = s[i - 1] ^ s[n] ^ s[i];
        if (w[i] == other) {
            cout << w[i] << '\n';
            return;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int T;
    cin >> T;
    while (T--) solve();

    return 0;
}