1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 15:48:42 +00:00

【实践课外】3.选择结构2

This commit is contained in:
Baoshuo Ren 2024-10-23 11:12:50 +08:00
parent 004727e0d3
commit 52dcc31283
Failed to extract signature
14 changed files with 201 additions and 0 deletions

View File

@ -0,0 +1,52 @@
#include <stdio.h>
int main() {
int a, b, c, d, e;
int ans_odd = 0, ans_even = 0;
scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
if (a % 2 == 0) {
ans_even += a * a;
} else {
ans_odd += a * a;
}
if (b % 2 == 0) {
ans_even += b * b;
} else {
ans_odd += b * b;
}
if (c % 2 == 0) {
ans_even += c * c;
} else {
ans_odd += c * c;
}
if (d % 2 == 0) {
ans_even += d * d;
} else {
ans_odd += d * d;
}
if (e % 2 == 0) {
ans_even += e * e;
} else {
ans_odd += e * e;
}
if (ans_odd == 0) {
printf("No Odd Number\n");
} else {
printf("%d\n", ans_odd);
}
if (ans_even == 0) {
printf("No Even Number\n");
} else {
printf("%d\n", ans_even);
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 KiB

View File

@ -0,0 +1,18 @@
#include <math.h>
#include <stdio.h>
int main() {
double x, y;
scanf("%lf%lf", &x, &y);
if (x <= 0 && y >= 0 || x <= y && y <= 0) {
printf("\\^O^/\n");
} else if (x > y && y <= 0) { // 类似 -0.5 -0.75 的情况
printf("1\n");
} else {
printf("%d\n", (int)ceil(y / x));
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
int n, m;
scanf("%d%d", &n, &m);
if (n >= m + 1 && n % (m + 1) == 0) {
printf("Second win\n");
} else {
printf("First win\n");
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 KiB

View File

@ -0,0 +1,36 @@
#include <stdio.h>
int main() {
int score;
scanf("%d", &score);
switch (score / 10) {
case 10:
case 9:
printf("A\n");
break;
case 8:
printf("B\n");
break;
case 7:
printf("C\n");
break;
case 6:
printf("D\n");
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
printf("E\n");
break;
default:
printf("Input error!\n");
break;
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 KiB

View File

@ -0,0 +1,19 @@
#include <stdio.h>
int main() {
int x1, y1, x2, y2, x3, y3;
scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3);
int d1 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
int d2 = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
int d3 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
if (d1 + d2 == d3) {
printf("yes\n");
} else {
printf("no\n");
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 KiB

View File

@ -0,0 +1,32 @@
#include <stdio.h>
int main() {
int id, avg_score, dis_score, is_cadre, paper_num;
int ans = 0;
scanf("%d%d%d%d%d", &id, &avg_score, &dis_score, &is_cadre, &paper_num);
// 院士奖学金
if (avg_score > 80 && paper_num >= 1) {
ans += 8000;
}
// 五四奖学金
if (avg_score > 85 && dis_score > 80) {
ans += 4000;
}
// 成绩优秀奖
if (avg_score > 90) {
ans += 2000;
}
// 班级贡献奖
if (dis_score > 80 && is_cadre) {
ans += 850;
}
printf("%d\n", ans);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

View File

@ -0,0 +1,29 @@
#include <stdio.h>
int main() {
double open, high, low, close;
scanf("%lf%lf%lf%lf", &open, &high, &low, &close);
if (close < open) {
printf("BW-Solid");
} else if (close > open) {
printf("R-Hollow");
} else {
printf("R-Cross");
}
if (low < open && low < close || high > open && high > close) {
printf(" with ");
if (low < open && low < close && high > open && high > close) {
printf("Lower Shadow and Upper Shadow");
} else if (low < open && low < close) {
printf("Lower Shadow");
} else { // high > open && high > close
printf("Upper Shadow");
}
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 KiB