两个不及格布尔值不同,恰好一门课不及格。
OJ: noi_openjudge
题目 ID: ch0104-10
难度:入门
标签:条件判断python
日期: 2026-07-30 23:01
题意
判断语文和数学是否恰好只有一门不及格。
思路
令两个布尔值分别表示 chinese < 60、math < 60。它们一真一假时才满足题意,Python 中布尔值的 != 恰好表示这种异或关系。
代码
Python代码
python
chinese, math = map(int, input().split())
print(int((chinese < 60) != (math < 60)))C++代码
cpp
#include <cstdio>
int main(){
int a,b;
scanf("%d%d",&a,&b);
if(( a < 60 && b >= 60) || ( b < 60 && a >= 60 ))
printf("1");
else
printf("0");
return 0;
}复杂度
时间复杂度和额外空间复杂度均为
总结
“恰好一个”是异或条件;对布尔值可直接写 condition1 != condition2。