本页面包含课程例题、课后拓展5关、代码填空4关的完整答案与家长辅导建议。
请输入本讲访问密码:
课程辅导解析(家长端) · 含全部例题、拓展、代码填空答案
#include <iostream>
using namespace std;
int main() {
for (int a = 1; a <= 50; a++) {
for (int b = 1; b <= 50; b++) {
if (a + b == 50) { // ★ 两个等号判断相等
cout << a << ' ' << b << endl;
}
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a[30] = {21,29,14,41,9,51,20,33,78,49,
56,66,36,63,87,98,62,76,93,81,
49,19,21,25,78,25,54,44,8,12};
for (int i = 0; i < 30; i++) {
for (int j = i + 1; j < 30; j++) { // ★ j从i+1开始,去重
if (a[i] + a[j] == 50) {
cout << a[i] << ' ' << a[j] << endl;
}
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
for (int a = 0; a <= 20; a++) { // 公鸡0~20
for (int b = 0; b <= 33; b++) { // 母鸡0~33
int c = 100 - a - b; // ★ 小鸡=总数-公鸡-母鸡
if (c % 3 == 0 && 5*a + 3*b + c/3 == 100) {
cout << a << ' ' << b << ' ' << c << endl;
}
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
for (int a = 1; a <= 50; a++) {
for (int b = 1; b <= 50; b++) { // ★ <= 包含50
if (a + b == 50) { // ★ == 两个等号
cout << a << ' ' << b << endl;
}
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n; cin >> n;
for (int a = 0; a <= n / 5; a++) { // ★ 公鸡5文一只
for (int b = 0; b <= n / 3; b++) {
int c = n - a - b; // ★ 小鸡=总数-公鸡-母鸡
if (c % 3 == 0 && 5*a + 3*b + c/3 == n) {
cout << a << ' ' << b << ' ' << c << endl;
}
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a[10] = {21,29,14,41,9,19,25,25,8,12};
for (int i = 0; i < 10; i++) {
for (int j = i + 1; j < 10; j++) { // ★ j在i后面
if (a[i] + a[j] == 50) { // ★ 判断和
cout << a[i] << ' ' << a[j] << endl;
}
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int k; cin >> k;
int cnt = 0;
for (int x = 1; x < 50; x++) {
for (int y = 1; y < 50; y++) {
int sum = 3 * x + 4 * y;
if (sum >= k) { // ★ 达到k分以上才通关
cnt++; // ★ 方案数+1
}
}
}
cout << cnt; // 输入200输出888
return 0;
}