#include <iostream>
#include <string>
using namespace std;
int main()
{
while (true){
string strX, strY;
bool x = false, y = false;
cout << "x = ";
cin >> strX;
if (strX == "true") {
x = true;
}
cout << "y = ";
cin >> strY;
if (strY == "true") {
y = true;
}
cout << "x xor y = ";
if (x ^ y){
cout << "true";
}
else{
cout << "false";
}
cout << endl;
}
return 0;
}
与 或 异或都是按照二进制进行计算的,转成二进制按照上面的规则进行计算
这是我的代码,望采纳
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y;
cout<<"输入x:";
cin>>x;
cout<<"输入y:";
cin>>y;
if(x^y==1) cout<<"true"<<endl;
else cout<<"false"<<endl;
return 0;
}