题解 | 异或和

异或和

https://www.nowcoder.com/practice/27e4dbdf6975414fbef67309311916f9

#include <bits/stdc++.h>
using namespace std;

#define int long long 
//一边输入一边异或即可 因为x ^ x = 0,0 ^ x = x ,所以出现偶数次数异或和的为0,所以我们可以这样
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n ;
int ans = 0;
for(int i = 0;i < n;i++)
{
    int x; 
    cin >> x;
    ans ^= x ;
}
    cout << ans << "\n";
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务