题解 | 异或和喵

异或和

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

x\oplus x=0,所以偶数个相同的数异或起来是零,奇数个相同的数异或起来是自身喵~所以答案就是所有数异或起来喵~

#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int Read() {
    int res = 0;
    char c = getchar();
    while (!isdigit(c)) {
        c = getchar_unlocked();
    }
    while (isdigit(c)) {
        res = res * 10 + (c - '0');
        c = getchar_unlocked();
    }
    return res;
}

void Solve() {
    int res = 0;
    int n = Read();
    while (n--) {
        res ^= Read();
    }
    cout << res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Solve();
}
// 64 位输出请用 printf("%lld")

全部评论
miaomiaomiao~
点赞 回复 分享
发布于 04-23 09:32 河北

相关推荐

代码飞升AL:同学院本 你这都是无效实习和跳槽 下一段底线是去一个稍微知名的公司 本质是骑驴找马 你这一直骑驴换来换去没什么区别
双非有机会进大厂吗
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
4
收藏
分享

创作者周榜

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