gpt4 book ai didi

c++ - 是否有任何特殊的 C++ 函数来获取数组所有元素的异或?

转载 作者:行者123 更新时间:2023-12-05 08:46:18 24 4
gpt4 key购买 nike

我有一个这样的数组 [1, 0, 1, 1, 0, 0, ...]

我怎样才能得到这个表达式的结果:1 XOR 0 XOR 1 XOR 1 XOR... 没有循环?

最佳答案

在 C++14 中:

std::accumulate(arr.begin(),
arr.end(),
0,
std::bit_xor<void>())

关于c++ - 是否有任何特殊的 C++ 函数来获取数组所有元素的异或?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69898756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com