2.用XOR做運算
#include<iostream>
using namespace std;
int main()
{
int n,num,sum,flag;
int arr[8] = {0};
num = 0;
sum = 0;
cin >> n;
int p[100];
int b[100] = {0};
for (int j = 0;j < n; j++)
{
cin >> p[j];
}
for (int k = 0;k < n; k++)
{
for (int x = 7;x >= 0; x--)
{
arr[x] = p[k] % 2;
p[k] /= 2;
}
int y = 1;
for (int x = 7;x >= 0; x--)
{
b[k] += arr[x] * y;
y *= 10;
}
}
for (int z = 0;z < n; z++)
{
if (z == 0)
num = b[z];
else
num = num ^ b[z];
}
flag = num ^ 0;
if (flag != 0)
cout << "yes" << endl;
else
cout << "no" << endl;
return 0;
}
為甚麼用XOR去做運算 就可以知道是贏是輸
回覆刪除Chasel 可以參考尼姆遊戲的相關資料
刪除