分支结构测试A 改错
冯宇麒
第四题 青少年模式
题目描述
本题是让我们计算,对于未满18周岁的子涵同学,在星期n的a点b分,以及节假日的状态c,他是否能进入游戏。
解题思路
1.定义变量 2.四种情况分别判断 3.根据不同情况输出
错误原因
判断不完全
AC代码
#include <iostream>
using namespace std;
int main() {
int a, b, c;
char d;
cin >> a >> b >> c >> d;
int e = 0;
int f = 0;
if (d == 'y') {
e = 1;
}
if (a == 5) {
e = 1;
}
if (a == 6) {
e = 1;
}
if (a == 7) {
e = 1;
}
if (b == 20) {
f = 1;
}
if (b == 21 && c == 0) {
f = 1;
}
if (e == 1 && f == 1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}第五题 原石
题目描述
本题是让我们计算,在a年的2月份,子涵在2月份能获取多少原石数。
解题思路
1.定义变量 2.四种情况分别判断 3.根据不同情况输出
错误原因
判断不完全
AC代码
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int c = 28;
if ((a % 4 == 0 && a % 100 != 0) || (a % 400 == 0)) {
c = 29;
}
int d = 60 * c;
int e = 0;
if (b == 1) {
e = 90 * c;
}
cout << d + e << endl;
return 0;
}第六题 药剂
题目描述
本题是让我们计算,阿贝多先生生成药剂4和药剂5各多少毫升。
解题思路
1.定义变量 2.四种情况分别判断 3.根据不同情况输出
错误原因
题目理解有误
AC代码
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double a, b, c, d;
cin >> a >> b >> c;
if (a > b) d = a, a = b, b = d;
if (a > c) d = a, a = c, c = d;
if (b > c) d = b, b = c, c = d;
cout << fixed << setprecision(2);
cout << a * (b / 2) << " " << (b / 2 + c) * (b / 2 + c) << endl;
return 0;
}