22 条题解
-
0
#include <bits/stdc++.h> using namespace std; int n,m; bool b=true ; int main() { cin>>n>>m; if(n<60&&m>=60||n>=60&&m<60){ cout<<"1"; } else{ cout<<"0"; } }
- 包含头文件
<bits/stdc++.h>
:这是一个非标准的头文件,通常在某些编译器(如GCC)中可用,用于包含几乎所有标准库头文件。使用这个头文件可以方便编程。 - 使用命名空间
std
:这样可以直接使用标准库中的对象和函数,而不需要每次都加上std::
前缀。 - 定义全局变量
n
和m
,用于存储从输入中读取的两个整数。 - 定义全局布尔变量
b
并初始化为true
。但这个变量在代码中并没有被使用,因此是多余的。 - 定义
main
函数,它是C++程序的入口点。 - 在
main
函数中,从标准输入读取两个整数n
和m
。 - 使用
if
语句判断n
和m
的值:- 如果
n
小于60且m
大于或等于60,或者n
大于或等于60且m
小于60,则输出 "1"。 - 否则,输出 "0"。
- 如果
注意,如果出现下列警告不用管 foo.cc: In function 'int main()': foo.cc:8:12: warning: suggest parentheses around '&&' within '||' [-Wparentheses] if(n<60&&m>=60||n>=60&&m<60){ ~~~~^~~~~~~
- 包含头文件
-
-1
有一门课不及格的学生
思路
刚好只有一门课不及格,所以不是语文不及格、数学及格,就是数学不及格、语文及格,要用“&&”和“||”
获取两门功课成绩,判断两门功课((语文 < 60 && 数学 >= 60) || (数学 < 60 && 语文 >= 60))
参考代码
#include <iostream> using namespace std; int main() { int c, m; cin >> c >> m; if ((c < 60 && m >= 60) || (m < 60 && c >= 60)) { cout << 1 << endl; } else { cout << 0 << endl; } return 0; }
-
-1
我也发一个😄 :
#include <iostream> using namespace std; int main() { int chinese, math; cin >> chinese >> math; if ( (chinese < 60 && math >= 60) || (math < 60 && chinese >= 60) ) // 易错易错!! 是恰好“一”科 不及格 输出1! //这也意味着 要么 语文不及格,数学及格了。 // 要么 数学不及格, 语文及格了。两种情况就用 ||。 cout << 1; else cout << 0; return 0; }
有错误请指出🚀️ 🚀️
点个赞哦👍
-
-1
#include <iostream> using namespace std; int main() { int a,b; cin >> a >> b; if ((a < 60 && b >= 60)||(a >= 60 && b < 60)) cout << "1"; else cout << "0"; return 0; }
解析: 判断成绩是否小于60,如果有就输出1,没有就输出0。
注意!!!!!! 只能有一门不及格,两门也不行(我一开始就栽在这,对九错一,懵逼了好久) 最后提醒大家,不管做练习还是考试审题都要仔细哦! 看到这里就点个赞吧!👍
-
-1
一个有点离谱的解法 思路: 由题意得:分数总共有三种情况 ①都小于60 (Chinese < 60 && Maths < 60) ②有一科小于60 (Chinese < 60 || Maths < 60) ③都不小于60(我将这种情况放在了else下面,写成条件表达式即为(Chinese > 60 && Maths > 60) 所以只需要用if-else if-else分别判断三种情况就好了
#include <iostream> using namespace std; int main() { int Chinese,Maths; cin >> Chinese >> Maths; if (Chinese < 60 && Maths < 60) cout << 0; else if (Chinese < 60 || Maths < 60) cout << 1; else cout << 0; return 0; }
信息
- ID
- 149
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 3602
- 已通过
- 983
- 上传者