【实践课外】2.选择结构1
17
【实践课外】2.选择结构1/7-1 三天打鱼两天晒网.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课外】2.选择结构1/7-1 三天打鱼两天晒网.jpg
Normal file
After Width: | Height: | Size: 331 KiB |
51
【实践课外】2.选择结构1/7-2 21选择-个人所得税.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课外】2.选择结构1/7-2 21选择-个人所得税.jpg
Normal file
After Width: | Height: | Size: 356 KiB |
27
【实践课外】2.选择结构1/7-3 计算天数.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课外】2.选择结构1/7-3 计算天数.jpg
Normal file
After Width: | Height: | Size: 328 KiB |
33
【实践课外】2.选择结构1/7-4 21选择-手表调整.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课外】2.选择结构1/7-4 21选择-手表调整.jpg
Normal file
After Width: | Height: | Size: 321 KiB |
18
【实践课外】2.选择结构1/7-5 21选择-最短完成时间.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课外】2.选择结构1/7-5 21选择-最短完成时间.jpg
Normal file
After Width: | Height: | Size: 363 KiB |
24
【实践课外】2.选择结构1/7-6 三角形判断.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课外】2.选择结构1/7-6 三角形判断.jpg
Normal file
After Width: | Height: | Size: 330 KiB |
44
【实践课外】2.选择结构1/7-7 求一元二次方程的根.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课外】2.选择结构1/7-7 求一元二次方程的根.jpg
Normal file
After Width: | Height: | Size: 601 KiB |