diff --git a/【实践课外】2.选择结构1/7-1 三天打鱼两天晒网.c b/【实践课外】2.选择结构1/7-1 三天打鱼两天晒网.c new file mode 100644 index 0000000..92663a3 --- /dev/null +++ b/【实践课外】2.选择结构1/7-1 三天打鱼两天晒网.c @@ -0,0 +1,17 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + int d = n % 5; + + if (1 <= d && d <= 3) { + printf("Fishing in day %d\n", n); + } else { + printf("Drying in day %d\n", n); + } + + return 0; +} diff --git a/【实践课外】2.选择结构1/7-1 三天打鱼两天晒网.jpg b/【实践课外】2.选择结构1/7-1 三天打鱼两天晒网.jpg new file mode 100644 index 0000000..e6bb4ec Binary files /dev/null and b/【实践课外】2.选择结构1/7-1 三天打鱼两天晒网.jpg differ diff --git a/【实践课外】2.选择结构1/7-2 21选择-个人所得税.c b/【实践课外】2.选择结构1/7-2 21选择-个人所得税.c new file mode 100644 index 0000000..127cb5f --- /dev/null +++ b/【实践课外】2.选择结构1/7-2 21选择-个人所得税.c @@ -0,0 +1,51 @@ +#include + +int main() { + double n, ans = 0; + + scanf("%lf", &n); + + if (0 < n && n < 36000) { + ans += 0.03 * n; + } else if (n >= 36000) { + ans += 0.03 * 36000; + } + + if (36000 <= n && n < 144000) { + ans += 0.1 * (n - 36000); + } else if (n >= 144000) { + ans += 0.1 * (144000 - 36000); + } + + if (144000 <= n && n < 300000) { + ans += 0.2 * (n - 144000); + } else if (n >= 300000) { + ans += 0.2 * (300000 - 144000); + } + + if (300000 <= n && n < 420000) { + ans += 0.25 * (n - 300000); + } else if (n >= 420000) { + ans += 0.25 * (420000 - 300000); + } + + if (420000 <= n && n < 660000) { + ans += 0.3 * (n - 420000); + } else if (n >= 660000) { + ans += 0.3 * (660000 - 420000); + } + + if (660000 <= n && n < 960000) { + ans += 0.35 * (n - 660000); + } else if (n >= 960000) { + ans += 0.35 * (960000 - 660000); + } + + if (960000 <= n) { + ans += 0.45 * (n - 960000); + } + + printf("%.2lf\n", ans); + + return 0; +} diff --git a/【实践课外】2.选择结构1/7-2 21选择-个人所得税.jpg b/【实践课外】2.选择结构1/7-2 21选择-个人所得税.jpg new file mode 100644 index 0000000..8a71b6d Binary files /dev/null and b/【实践课外】2.选择结构1/7-2 21选择-个人所得税.jpg differ diff --git a/【实践课外】2.选择结构1/7-3 计算天数.c b/【实践课外】2.选择结构1/7-3 计算天数.c new file mode 100644 index 0000000..f65b921 --- /dev/null +++ b/【实践课外】2.选择结构1/7-3 计算天数.c @@ -0,0 +1,27 @@ +#include + +const int DAYS[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30}; + +int main() { + int y, m, d; + + scanf("%4d/%2d/%2d", &y, &m, &d); + + int days = 0; + + for (int i = 1; i < m; i++) { + days += DAYS[i]; + + if (i == 2) { // 2 月涉及到闰年 + if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) { + days++; + } + } + } + + days += d; + + printf("%d\n", days); + + return 0; +} diff --git a/【实践课外】2.选择结构1/7-3 计算天数.jpg b/【实践课外】2.选择结构1/7-3 计算天数.jpg new file mode 100644 index 0000000..08b5fa0 Binary files /dev/null and b/【实践课外】2.选择结构1/7-3 计算天数.jpg differ diff --git a/【实践课外】2.选择结构1/7-4 21选择-手表调整.c b/【实践课外】2.选择结构1/7-4 21选择-手表调整.c new file mode 100644 index 0000000..61d620c --- /dev/null +++ b/【实践课外】2.选择结构1/7-4 21选择-手表调整.c @@ -0,0 +1,33 @@ +#include + +int main() { + int hh, mm, ss; + + scanf("%d:%d:%d", &hh, &mm, &ss); + + int time_seconds = hh * 3600 + mm * 60 + ss; + int news_seconds = 19 * 3600; + int divide_seconds = 7 * 3600; + + if (time_seconds <= divide_seconds) { + time_seconds += 24 * 3600; + } + + if (time_seconds > news_seconds) { + int diff_seconds = time_seconds - news_seconds; + int diff_hh = diff_seconds / 3600; + int diff_mm = diff_seconds % 3600 / 60; + int diff_ss = diff_seconds % 60; + + printf("+%02d:%02d:%02d\n", diff_hh, diff_mm, diff_ss); + } else { + int diff_seconds = news_seconds - time_seconds; + int diff_hh = diff_seconds / 3600; + int diff_mm = diff_seconds % 3600 / 60; + int diff_ss = diff_seconds % 60; + + printf("-%02d:%02d:%02d\n", diff_hh, diff_mm, diff_ss); + } + + return 0; +} diff --git a/【实践课外】2.选择结构1/7-4 21选择-手表调整.jpg b/【实践课外】2.选择结构1/7-4 21选择-手表调整.jpg new file mode 100644 index 0000000..1bf590c Binary files /dev/null and b/【实践课外】2.选择结构1/7-4 21选择-手表调整.jpg differ diff --git a/【实践课外】2.选择结构1/7-5 21选择-最短完成时间.c b/【实践课外】2.选择结构1/7-5 21选择-最短完成时间.c new file mode 100644 index 0000000..b861ff2 --- /dev/null +++ b/【实践课外】2.选择结构1/7-5 21选择-最短完成时间.c @@ -0,0 +1,18 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + int ans1 = n * 7; + int ans2 = 15 + n * 5; + + if (ans1 < ans2) { + printf("%d\n", ans1); + } else { + printf("%d\n", ans2); + } + + return 0; +} diff --git a/【实践课外】2.选择结构1/7-5 21选择-最短完成时间.jpg b/【实践课外】2.选择结构1/7-5 21选择-最短完成时间.jpg new file mode 100644 index 0000000..dad55e1 Binary files /dev/null and b/【实践课外】2.选择结构1/7-5 21选择-最短完成时间.jpg differ diff --git a/【实践课外】2.选择结构1/7-6 三角形判断.c b/【实践课外】2.选择结构1/7-6 三角形判断.c new file mode 100644 index 0000000..1e25281 --- /dev/null +++ b/【实践课外】2.选择结构1/7-6 三角形判断.c @@ -0,0 +1,24 @@ +#include +#include + +int main() { + double x1, y1, x2, y2, x3, y3; + + scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3); + + double len1 = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); + double len2 = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)); + double len3 = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)); + + if (len1 + len2 <= len3 || len1 + len3 <= len2 || len2 + len3 <= len1) { + printf("Impossible\n"); + } else { + double l = len1 + len2 + len3; + double p = l / 2; + double s = sqrt(p * (p - len1) * (p - len2) * (p - len3)); + + printf("L = %.2lf, A = %.2lf\n", l, s); + } + + return 0; +} diff --git a/【实践课外】2.选择结构1/7-6 三角形判断.jpg b/【实践课外】2.选择结构1/7-6 三角形判断.jpg new file mode 100644 index 0000000..6e6413c Binary files /dev/null and b/【实践课外】2.选择结构1/7-6 三角形判断.jpg differ diff --git a/【实践课外】2.选择结构1/7-7 求一元二次方程的根.c b/【实践课外】2.选择结构1/7-7 求一元二次方程的根.c new file mode 100644 index 0000000..eb6576e --- /dev/null +++ b/【实践课外】2.选择结构1/7-7 求一元二次方程的根.c @@ -0,0 +1,44 @@ +#include +#include + +double no_neg_zero(double x) { + return x == -0.0 ? 0.0 : x; +} + +int main() { + double a, b, c; + + scanf("%lf %lf %lf", &a, &b, &c); + + if (a == 0 && b == 0) { + if (c == 0) { + printf("Zero Equation\n"); + } else { + printf("Not An Equation\n"); + } + } else if (a == 0) { + double x = -c / b; + + printf("%.2lf\n", no_neg_zero(x)); + } else { + double delta = b * b - 4.0 * a * c; + + if (delta > 0) { + double x1 = (-b + sqrt(delta)) / (2 * a); + double x2 = (-b - sqrt(delta)) / (2 * a); + + printf("%.2lf\n%.2lf\n", no_neg_zero(x1), no_neg_zero(x2)); + } else if (delta == 0) { + double x = -b / (2 * a); + + printf("%.2lf\n", no_neg_zero(x)); + } else if (delta < 0) { + double real = -b / (2 * a); + double imag = sqrt(-delta) / (2 * a); + + printf("%.2lf+%.2lfi\n%.2lf-%.2lfi\n", no_neg_zero(real), no_neg_zero(imag), no_neg_zero(real), no_neg_zero(imag)); + } + } + + return 0; +} diff --git a/【实践课外】2.选择结构1/7-7 求一元二次方程的根.jpg b/【实践课外】2.选择结构1/7-7 求一元二次方程的根.jpg new file mode 100644 index 0000000..d7c6a07 Binary files /dev/null and b/【实践课外】2.选择结构1/7-7 求一元二次方程的根.jpg differ