一、原题
链接:Training on Exclusive "or" (xor) Logical Operator | Codewars
Exclusive "or" (xor) Logical Operator Overview In some scripting languages like PHP, there exists a logical operator (e.g. |
测试用例
false xor false == false // since both are false true xor false == true // exactly one of the two expressions are true false xor true == true // exactly one of the two expressions are true true xor true == false // Both are true. "xor" only returns true if EXACTLY one of the two expressions evaluate to true. |
二、解题
1、分析
两者相同返回false,两者不同返回true。
2、思路
(1)a==b return false;
(2)a!=b return true;
三、Myway
#include <stdbool.h>bool xor(bool a, bool b) {if(a==b)return false;elsereturn true;
}