C练手题--Exclusive “or“ (xor) Logical Operator 【8 kyu】

一、原题

链接: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. &&, ||, and, or, etc.) called the "Exclusive Or" (hence the name of this Kata). The exclusive or evaluates two booleans. It then returns true if exactly one of the two expressions are true , false otherwise. For example: |

测试用例

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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

cs 复制代码
#include <stdbool.h>

bool xor(bool a, bool b) {
  if(a==b)
     
    return false;
  else
    return true;
}
相关推荐
夕除6 分钟前
spring boot--08
开发语言·windows·python
狐狐生风12 分钟前
Python UV 完整安装教程
开发语言·python·uv
Kiyra16 分钟前
限流不是加个计数器就行:用 Lua 脚本实现多维度原子限流
开发语言·人工智能·网络协议·职场和发展·架构·lua·ai-native
雨落在了我的手上18 分钟前
初识java(二):数据类型与变量
java·开发语言
xcjbqd028 分钟前
提升Python编程效率的五大特性
开发语言·python
平凡但不平庸的码农34 分钟前
Go GMP 调度模型详解
开发语言·后端·golang
2401_8784545340 分钟前
js的复习(一)
开发语言·javascript·ecmascript
旺仔老馒头.40 分钟前
【C++】类和对象(二)
开发语言·c++·后端·类和对象
等故意42 分钟前
C# 工业视觉上位机开发心得分享
开发语言·数码相机·c#·视觉检测
广师大-Wzx43 分钟前
JavaWeb:后端部分
java·开发语言·spring·servlet·tomcat·maven·mybatis