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;
}
相关推荐
AKA__Zas8 小时前
初识多线程(初初识)
java·服务器·开发语言·学习方法
zhangrelay8 小时前
三分钟云课实践速通--概率统计--python版
linux·开发语言·笔记·python·学习·ubuntu
张赐荣8 小时前
深入详解在 Python 中用 ctypes 调用 Windows API 清空回收站
开发语言·windows·python
三品吉他手会点灯8 小时前
STM32 VSCode 开发-C语言程序运行后,终端中文乱码
c语言·ide·笔记·vscode·stm32·学习·编辑器
彷徨而立8 小时前
【C/C++】在头文件中定义全局变量的方法
c语言·开发语言·c++
我命由我123458 小时前
Android 广播 - 显式广播与隐式广播
android·java·开发语言·java-ee·kotlin·android studio·android-studio
不知名的老吴8 小时前
聊一聊年轻的编程语言Golang与Rust
开发语言·golang·rust
我不是懒洋洋8 小时前
手写一个跳表:从原理到Redis级实现
c语言
小何code8 小时前
【Python零基础入门】第6篇:Python字符串入门:创建、索引与切片
开发语言·python