异或可以解决很多奇特的算法问题。请时刻记住异或!
参考
实验代码
//
// main.cpp
// xor
//
// Created by SteveWong on 8/4/16.
// Copyright © 2016 SteveWong. All rights reserved.
//
#include <iostream>
#include <vector>
using namespace std;
void vprint(vector<int> res)
{
for (auto i : res)
cout << i << " ";
cout << endl;
}
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
const int len = 10;
vector<int> v;
for (int i = 0; i < len; i++)
{
v.push_back(rand());
}
vector<int> v0 = v;
v.push_back(12345);
int res = 0;
for (int i = 0; i < len; i++)
{
res ^= v[i];
res ^= v0[i];
}
res ^= v[len];
vprint(v);
vprint(v0);
cout << res << endl;
return 0;
}