sansa-and-xor: initial commit
This commit is contained in:
parent
9c577f8a75
commit
25ad456187
2 changed files with 30 additions and 0 deletions
1
algorithms/bit-manipulation/sansa-and-xor/README.md
Normal file
1
algorithms/bit-manipulation/sansa-and-xor/README.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
<https://www.hackerrank.com/challenges/sansa-and-xor>
|
||||
29
algorithms/bit-manipulation/sansa-and-xor/solution.cpp
Normal file
29
algorithms/bit-manipulation/sansa-and-xor/solution.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace std;
|
||||
size_t T;
|
||||
cin >> T;
|
||||
|
||||
while (T--) {
|
||||
|
||||
size_t N;
|
||||
cin >> N;
|
||||
|
||||
int value, result;
|
||||
result = 0;
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
|
||||
cin >> value;
|
||||
|
||||
if (((i + 1) & 1) && ((N - i) & 1))
|
||||
result ^= value;
|
||||
}
|
||||
|
||||
cout << (result^0) << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue