From ddd64d9607266a390e04856cb765450e3643aa28 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 30 Oct 2024 23:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=A2=9D=E5=A4=96=E7=BB=83=E4=B9=A0?= =?UTF-8?q?=E3=80=91=E9=80=89=E6=8B=A9=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 【额外练习】选择结构/7-10 选择-三角形分类.c | 17 +++++++ .../7-11 选择-五分制转百分制.c | 21 ++++++++ 【额外练习】选择结构/7-12 选择-大小写转换.c | 15 ++++++ 【额外练习】选择结构/7-13 选择-体积最大.c | 17 +++++++ .../7-14 选择-N以内所有正整数和.c | 16 ++++++ 【额外练习】选择结构/7-15 选择-简易计算机.c | 51 +++++++++++++++++++ 【额外练习】选择结构/7-16 选择-简单的运算.c | 12 +++++ 【额外练习】选择结构/7-17 选择-水仙花数.c | 19 +++++++ 【额外练习】选择结构/7-18 选择-三角形面积.c | 17 +++++++ 【额外练习】选择结构/7-19 选择-完全平方数.c | 18 +++++++ .../7-20 选择-矩形与点的位置.c | 15 ++++++ 【额外练习】选择结构/7-21 选择-数的判别.c | 17 +++++++ 【额外练习】选择结构/7-22 选择-销售菜单.c | 31 +++++++++++ 【额外练习】选择结构/7-23 选择-电话费.c | 20 ++++++++ 【额外练习】选择结构/7-24 选择-税收计算1.c | 17 +++++++ 【额外练习】选择结构/7-25 选择-自然数.c | 15 ++++++ 【额外练习】选择结构/7-26 选择-宝藏.c | 31 +++++++++++ 【额外练习】选择结构/7-27 选择-回文数.c | 24 +++++++++ 【额外练习】选择结构/7-28 选择-时钟.c | 16 ++++++ .../7-29 选择-求解一元二次方程.c | 31 +++++++++++ 【额外练习】选择结构/7-30 选择-硬币游戏.c | 20 ++++++++ 【额外练习】选择结构/7-31 选择-猜数字游戏.c | 29 +++++++++++ 【额外练习】选择结构/7-32 选择-扑克.c | 21 ++++++++ 【额外练习】选择结构/7-8 选择-买奶茶.c | 19 +++++++ 【额外练习】选择结构/7-9 选择-三角形判别.c | 15 ++++++ 25 files changed, 524 insertions(+) create mode 100644 【额外练习】选择结构/7-10 选择-三角形分类.c create mode 100644 【额外练习】选择结构/7-11 选择-五分制转百分制.c create mode 100644 【额外练习】选择结构/7-12 选择-大小写转换.c create mode 100644 【额外练习】选择结构/7-13 选择-体积最大.c create mode 100644 【额外练习】选择结构/7-14 选择-N以内所有正整数和.c create mode 100644 【额外练习】选择结构/7-15 选择-简易计算机.c create mode 100644 【额外练习】选择结构/7-16 选择-简单的运算.c create mode 100644 【额外练习】选择结构/7-17 选择-水仙花数.c create mode 100644 【额外练习】选择结构/7-18 选择-三角形面积.c create mode 100644 【额外练习】选择结构/7-19 选择-完全平方数.c create mode 100644 【额外练习】选择结构/7-20 选择-矩形与点的位置.c create mode 100644 【额外练习】选择结构/7-21 选择-数的判别.c create mode 100644 【额外练习】选择结构/7-22 选择-销售菜单.c create mode 100644 【额外练习】选择结构/7-23 选择-电话费.c create mode 100644 【额外练习】选择结构/7-24 选择-税收计算1.c create mode 100644 【额外练习】选择结构/7-25 选择-自然数.c create mode 100644 【额外练习】选择结构/7-26 选择-宝藏.c create mode 100644 【额外练习】选择结构/7-27 选择-回文数.c create mode 100644 【额外练习】选择结构/7-28 选择-时钟.c create mode 100644 【额外练习】选择结构/7-29 选择-求解一元二次方程.c create mode 100644 【额外练习】选择结构/7-30 选择-硬币游戏.c create mode 100644 【额外练习】选择结构/7-31 选择-猜数字游戏.c create mode 100644 【额外练习】选择结构/7-32 选择-扑克.c create mode 100644 【额外练习】选择结构/7-8 选择-买奶茶.c create mode 100644 【额外练习】选择结构/7-9 选择-三角形判别.c diff --git a/【额外练习】选择结构/7-10 选择-三角形分类.c b/【额外练习】选择结构/7-10 选择-三角形分类.c new file mode 100644 index 0000000..b6856c7 --- /dev/null +++ b/【额外练习】选择结构/7-10 选择-三角形分类.c @@ -0,0 +1,17 @@ +#include + +int main() { + int a, b, c; + + scanf("%d%d%d", &a, &b, &c); + + if (a == b && b == c) { + printf("bian\n"); + } else if (a == b || b == c || a == c) { + printf("yao\n"); + } else { + printf("triangle\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-11 选择-五分制转百分制.c b/【额外练习】选择结构/7-11 选择-五分制转百分制.c new file mode 100644 index 0000000..07f488f --- /dev/null +++ b/【额外练习】选择结构/7-11 选择-五分制转百分制.c @@ -0,0 +1,21 @@ +#include + +int main() { + char grade; + + scanf("%c", &grade); + + if (grade == 'A') { + printf("85~100\n"); + } else if (grade == 'B') { + printf("70~84\n"); + } else if (grade == 'C') { + printf("60~69\n"); + } else if (grade == 'D') { + printf("<60\n"); + } else { + printf("Error\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-12 选择-大小写转换.c b/【额外练习】选择结构/7-12 选择-大小写转换.c new file mode 100644 index 0000000..9e69797 --- /dev/null +++ b/【额外练习】选择结构/7-12 选择-大小写转换.c @@ -0,0 +1,15 @@ +#include + +int main() { + char c; + + scanf("%c", &c); + + if (c >= 'a' && c <= 'z') { + printf("%c\n", c - 32); + } else if (c >= 'A' && c <= 'Z') { + printf("%c\n", c + 32); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-13 选择-体积最大.c b/【额外练习】选择结构/7-13 选择-体积最大.c new file mode 100644 index 0000000..8726088 --- /dev/null +++ b/【额外练习】选择结构/7-13 选择-体积最大.c @@ -0,0 +1,17 @@ +#include + +int main() { + int a, b, c; + + scanf("%d%d%d", &a, &b, &c); + + if (a > b && a > c) { + printf("%d\n", a); + } else if (b > a && b > c) { + printf("%d\n", b); + } else { + printf("%d\n", c); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-14 选择-N以内所有正整数和.c b/【额外练习】选择结构/7-14 选择-N以内所有正整数和.c new file mode 100644 index 0000000..0e7d315 --- /dev/null +++ b/【额外练习】选择结构/7-14 选择-N以内所有正整数和.c @@ -0,0 +1,16 @@ +#include + +int main() { + int n; + int sum = 0; + + scanf("%d", &n); + + for (int i = 1; i <= n; i++) { + sum += i; + } + + printf("%d\n", sum); + + return 0; +} diff --git a/【额外练习】选择结构/7-15 选择-简易计算机.c b/【额外练习】选择结构/7-15 选择-简易计算机.c new file mode 100644 index 0000000..23eca21 --- /dev/null +++ b/【额外练习】选择结构/7-15 选择-简易计算机.c @@ -0,0 +1,51 @@ +#include + +int main() { + int x, a, b, c; + + scanf("%d%d%d%d", &x, &a, &b, &c); + + switch (x) { + case 0: + printf("%d", a + b); + break; + + case 1: + printf("%d", a - b); + break; + + case 2: + printf("%d", a * b); + break; + + case 3: + printf("%d", a / b); + break; + + case 4: + printf("%d", a % b); + break; + + case 5: + printf("%d", a ? b : c); + break; + + case 6: + printf("%d", a > b); + break; + + case 7: + printf("%d", a < b); + break; + + case 8: + printf("%d", a != b); + break; + + case 9: + printf("%d", a == b); + break; + } + + return 0; +} diff --git a/【额外练习】选择结构/7-16 选择-简单的运算.c b/【额外练习】选择结构/7-16 选择-简单的运算.c new file mode 100644 index 0000000..d056bd9 --- /dev/null +++ b/【额外练习】选择结构/7-16 选择-简单的运算.c @@ -0,0 +1,12 @@ +#include +#include + +int main() { + double n; + + scanf("%lf", &n); + + printf("%d %d %.5lf\n", (int)ceil(n), (int)floor(n), n); + + return 0; +} diff --git a/【额外练习】选择结构/7-17 选择-水仙花数.c b/【额外练习】选择结构/7-17 选择-水仙花数.c new file mode 100644 index 0000000..54682b6 --- /dev/null +++ b/【额外练习】选择结构/7-17 选择-水仙花数.c @@ -0,0 +1,19 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + int a = n / 100; + int b = n / 10 % 10; + int c = n % 10; + + if (n == a * a * a + b * b * b + c * c * c) { + printf("yes\n"); + } else { + printf("no\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-18 选择-三角形面积.c b/【额外练习】选择结构/7-18 选择-三角形面积.c new file mode 100644 index 0000000..f149db7 --- /dev/null +++ b/【额外练习】选择结构/7-18 选择-三角形面积.c @@ -0,0 +1,17 @@ +#include + +int main() { + double a, b, c; + + scanf("%lf%lf%lf", &a, &b, &c); + + if (a + b > c && a + c > b && b + c > a) { + double p = (a + b + c) / 2; + double s = sqrt(p * (p - a) * (p - b) * (p - c)); + printf("%.2lf %.2lf\n", s, a + b + c); + } else { + printf("no triangle\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-19 选择-完全平方数.c b/【额外练习】选择结构/7-19 选择-完全平方数.c new file mode 100644 index 0000000..18e7cc7 --- /dev/null +++ b/【额外练习】选择结构/7-19 选择-完全平方数.c @@ -0,0 +1,18 @@ +#include +#include + +int main() { + int n; + + scanf("%d", &n); + + int m = sqrt(n); + + if (m * m == n) { + printf("Yes\n"); + } else { + printf("No\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-20 选择-矩形与点的位置.c b/【额外练习】选择结构/7-20 选择-矩形与点的位置.c new file mode 100644 index 0000000..8084886 --- /dev/null +++ b/【额外练习】选择结构/7-20 选择-矩形与点的位置.c @@ -0,0 +1,15 @@ +#include + +int main() { + int xL, yL, xR, yR, x, y; + + scanf("%d%d%d%d%d%d", &xL, &yL, &xR, &yR, &x, &y); + + if (x >= xL && x <= xR && y <= yL && y >= yR) { + printf("Yes\n"); + } else { + printf("No\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-21 选择-数的判别.c b/【额外练习】选择结构/7-21 选择-数的判别.c new file mode 100644 index 0000000..62538f6 --- /dev/null +++ b/【额外练习】选择结构/7-21 选择-数的判别.c @@ -0,0 +1,17 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + if (n % 2 == 0) { + printf("%d is an even number\n", n); + } else if (n % 3 == 0) { + printf("%d is an odd number,it can be divided by 3\n", n); + } else { + printf("%d is an odd number,it can't be divided by 3\n", n); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-22 选择-销售菜单.c b/【额外练习】选择结构/7-22 选择-销售菜单.c new file mode 100644 index 0000000..1d86626 --- /dev/null +++ b/【额外练习】选择结构/7-22 选择-销售菜单.c @@ -0,0 +1,31 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + switch (n) { + case 1: + printf("8\n"); + break; + + case 2: + printf("4.5\n"); + break; + + case 3: + printf("12.8\n"); + break; + + case 4: + printf("3\n"); + break; + + default: + printf("Exit\n"); + break; + } + + return 0; +} diff --git a/【额外练习】选择结构/7-23 选择-电话费.c b/【额外练习】选择结构/7-23 选择-电话费.c new file mode 100644 index 0000000..0f83d02 --- /dev/null +++ b/【额外练习】选择结构/7-23 选择-电话费.c @@ -0,0 +1,20 @@ +#include + +int main() { + int t; + + scanf("%d", &t); + + double s1 = 25 + 0.1 * t; + double s2 = 20; + + if (t >= 100) s2 = 0.3 * t; + + if (s1 > s2) { + printf("2\n"); + } else { + printf("1\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-24 选择-税收计算1.c b/【额外练习】选择结构/7-24 选择-税收计算1.c new file mode 100644 index 0000000..18c30fd --- /dev/null +++ b/【额外练习】选择结构/7-24 选择-税收计算1.c @@ -0,0 +1,17 @@ +#include + +int main() { + int x; + + scanf("%d", &x); + + if (x <= 800) { + printf("0.0\n"); + } else if (x <= 4000) { + printf("%.1lf\n", (x - 800) * 0.15); + } else { + printf("%.1lf\n", x * 0.1); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-25 选择-自然数.c b/【额外练习】选择结构/7-25 选择-自然数.c new file mode 100644 index 0000000..0f3597e --- /dev/null +++ b/【额外练习】选择结构/7-25 选择-自然数.c @@ -0,0 +1,15 @@ +#include + +int main() { + double a; + + scanf("%lf", &a); + + if (a >= 0 && (int)a == a) { + printf("Yes\n"); + } else { + printf("No\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-26 选择-宝藏.c b/【额外练习】选择结构/7-26 选择-宝藏.c new file mode 100644 index 0000000..4baf3f1 --- /dev/null +++ b/【额外练习】选择结构/7-26 选择-宝藏.c @@ -0,0 +1,31 @@ +#include + +int main() { + int x; + + scanf("%d", &x); + + int canFill = 0; + + for (int a = 0; a <= x / 4; a++) { + for (int b = 0; b <= x / 5; b++) { + for (int c = 0; c <= x / 7; c++) { + // 计算当前组合的体积 + if (4 * a + 5 * b + 7 * c == x) { + canFill = 1; + break; + } + } + if (canFill) break; + } + if (canFill) break; + } + + if (canFill) { + printf("ni bu yao guo lai a!\n"); + } else { + printf("What a lucky day!\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-27 选择-回文数.c b/【额外练习】选择结构/7-27 选择-回文数.c new file mode 100644 index 0000000..b8bbfaf --- /dev/null +++ b/【额外练习】选择结构/7-27 选择-回文数.c @@ -0,0 +1,24 @@ +#include + +int main() { + int n; + int a, b, c, d, e, f, g; + + scanf("%d", &n); + + a = n / 1000000; + b = n / 100000 % 10; + c = n / 10000 % 10; + d = n / 1000 % 10; + e = n / 100 % 10; + f = n / 10 % 10; + g = n % 10; + + if (a == g && b == f && c == e) { + printf("Yes\n"); + } else { + printf("No\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-28 选择-时钟.c b/【额外练习】选择结构/7-28 选择-时钟.c new file mode 100644 index 0000000..39f7fd8 --- /dev/null +++ b/【额外练习】选择结构/7-28 选择-时钟.c @@ -0,0 +1,16 @@ +#include + +int main() { + int h, m; + + scanf("%d:%d", &h, &m); + + double angle = 30 * h - 5.5 * m; + + if (angle < 0) angle = -angle; + if (angle > 180) angle = 360 - angle; + + printf("%.3lf\n", angle); + + return 0; +} diff --git a/【额外练习】选择结构/7-29 选择-求解一元二次方程.c b/【额外练习】选择结构/7-29 选择-求解一元二次方程.c new file mode 100644 index 0000000..127613b --- /dev/null +++ b/【额外练习】选择结构/7-29 选择-求解一元二次方程.c @@ -0,0 +1,31 @@ +#include +#include + +int main() { + double a, b, c; + + scanf("%lf%lf%lf", &a, &b, &c); + + double delta = b * b - 4 * a * c; + + if (delta > 0) { + double x1 = (-b - sqrt(delta)) / (a * 2); + double x2 = (-b + sqrt(delta)) / (a * 2); + + if (x1 > x2) { + double temp = x1; + x1 = x2; + x2 = temp; + } + + printf("%.2lf %.2lf\n", x1, x2); + } else if (delta == 0) { + double x1 = -b / (a * 2); + + printf("%.2lf\n", x1); + } else { + printf("No solution\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-30 选择-硬币游戏.c b/【额外练习】选择结构/7-30 选择-硬币游戏.c new file mode 100644 index 0000000..7e0cd67 --- /dev/null +++ b/【额外练习】选择结构/7-30 选择-硬币游戏.c @@ -0,0 +1,20 @@ +#include + +int main() { + int a, b; + + scanf("%d%d", &a, &b); + + // [Theorem] + // In a normal nim game, the player making the first move has a winning strategy + // if and only if the nim-sum of the sizes of the heaps is not zero. Otherwise, + // the second player has a winning strategy. + // Source: https://en.wikipedia.org/wiki/Nim + if ((a ^ b) == 0) { + printf("abcdxyzk\n"); + } else { + printf("AekdyCoin\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-31 选择-猜数字游戏.c b/【额外练习】选择结构/7-31 选择-猜数字游戏.c new file mode 100644 index 0000000..0f9d973 --- /dev/null +++ b/【额外练习】选择结构/7-31 选择-猜数字游戏.c @@ -0,0 +1,29 @@ +#include + +int main() { + int total, andy, ban; + + scanf("%d%d%d", &total, &andy, &ban); + + int andyDiff = total - andy; + int banDiff = total - ban; + + if (andyDiff < 0) andyDiff = -andyDiff; + if (banDiff < 0) banDiff = -banDiff; + + if (andyDiff == banDiff) { + if (andy < ban) { + printf("Andy\n"); + } else if (andy == ban) { + printf("Peace\n"); + } else { + printf("Ban\n"); + } + } else if (andyDiff < banDiff) { + printf("Andy\n"); + } else { + printf("Ban\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-32 选择-扑克.c b/【额外练习】选择结构/7-32 选择-扑克.c new file mode 100644 index 0000000..c618515 --- /dev/null +++ b/【额外练习】选择结构/7-32 选择-扑克.c @@ -0,0 +1,21 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + if (n >= 1 && n <= 10) { + printf("%d\n", n); + } else if (n == 11) { + printf("J\n"); + } else if (n == 12) { + printf("Q\n"); + } else if (n == 13) { + printf("K\n"); + } else { + printf("NO\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-8 选择-买奶茶.c b/【额外练习】选择结构/7-8 选择-买奶茶.c new file mode 100644 index 0000000..e707c21 --- /dev/null +++ b/【额外练习】选择结构/7-8 选择-买奶茶.c @@ -0,0 +1,19 @@ +#include + +int main() { + int x; + + scanf("%d", &x); + + if (x == 5) { + printf("6\n"); + } else if (x == 6) { + printf("10\n"); + } else if (x == 7) { + printf("8\n"); + } else { + printf("4\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-9 选择-三角形判别.c b/【额外练习】选择结构/7-9 选择-三角形判别.c new file mode 100644 index 0000000..347c6a8 --- /dev/null +++ b/【额外练习】选择结构/7-9 选择-三角形判别.c @@ -0,0 +1,15 @@ +#include + +int main() { + int a, b, c; + + scanf("%d%d%d", &a, &b, &c); + + if (a + b > c && a + c > b && b + c > a) { + printf("Yes\n"); + } else { + printf("No\n"); + } + + return 0; +}