mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-23 09:38:42 +00:00
【实践课内】3.选择结构2
This commit is contained in:
parent
6896ba08ed
commit
004727e0d3
29
【实践课内】3.选择结构2/7-1 选择-星期.c
Normal file
29
【实践课内】3.选择结构2/7-1 选择-星期.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
n %= 7;
|
||||
|
||||
if (n == 0) {
|
||||
printf("Friday\n");
|
||||
} else if (n == 1) {
|
||||
printf("Saturday\n");
|
||||
} else if (n == 2) {
|
||||
printf("Sunday\n");
|
||||
} else if (n == 3) {
|
||||
printf("Monday\n");
|
||||
} else if (n == 4) {
|
||||
printf("Tuesday\n");
|
||||
} else if (n == 5) {
|
||||
printf("Wednesday\n");
|
||||
} else if (n == 6) {
|
||||
printf("Thursday\n");
|
||||
} else { // Wrong input
|
||||
printf("What're you doing?\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】3.选择结构2/7-1 选择-星期.jpg
Normal file
BIN
【实践课内】3.选择结构2/7-1 选择-星期.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 293 KiB |
52
【实践课内】3.选择结构2/7-2 21选择-我们是冠军.c
Normal file
52
【实践课内】3.选择结构2/7-2 21选择-我们是冠军.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int type;
|
||||
double s1, s2, s3;
|
||||
|
||||
scanf("%d%lf%lf%lf", &type, &s1, &s2, &s3);
|
||||
|
||||
if (type == 0) { // 赛跑,从低到高排序
|
||||
if (s1 > s2) {
|
||||
double temp = s1;
|
||||
s1 = s2;
|
||||
s2 = temp;
|
||||
}
|
||||
|
||||
if (s1 > s3) {
|
||||
double temp = s1;
|
||||
s1 = s3;
|
||||
s3 = temp;
|
||||
}
|
||||
|
||||
if (s2 > s3) {
|
||||
double temp = s2;
|
||||
s2 = s3;
|
||||
s3 = temp;
|
||||
}
|
||||
|
||||
printf("%.2lf %.2lf %.2lf\n", s1, s2, s3);
|
||||
} else { // type == 1
|
||||
if (s1 < s2) {
|
||||
double temp = s1;
|
||||
s1 = s2;
|
||||
s2 = temp;
|
||||
}
|
||||
|
||||
if (s1 < s3) {
|
||||
double temp = s1;
|
||||
s1 = s3;
|
||||
s3 = temp;
|
||||
}
|
||||
|
||||
if (s2 < s3) {
|
||||
double temp = s2;
|
||||
s2 = s3;
|
||||
s3 = temp;
|
||||
}
|
||||
|
||||
printf("%.2lf %.2lf %.2lf\n", s1, s2, s3);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】3.选择结构2/7-2 21选择-我们是冠军.jpg
Normal file
BIN
【实践课内】3.选择结构2/7-2 21选择-我们是冠军.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 328 KiB |
21
【实践课内】3.选择结构2/7-3 21选择-盘闰年.c
Normal file
21
【实践课内】3.选择结构2/7-3 21选择-盘闰年.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
// 判断闰年
|
||||
if ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0) {
|
||||
// 判断是否含 4
|
||||
if (n % 10 == 4 || n / 10 % 10 == 4 || n / 100 % 10 == 4 || n / 1000 % 10 == 4) {
|
||||
printf("panta!\n");
|
||||
} else {
|
||||
printf("1\n");
|
||||
}
|
||||
} else {
|
||||
printf("0\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】3.选择结构2/7-3 21选择-盘闰年.jpg
Normal file
BIN
【实践课内】3.选择结构2/7-3 21选择-盘闰年.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 318 KiB |
39
【实践课内】3.选择结构2/7-4 选择-合法日期.c
Normal file
39
【实践课内】3.选择结构2/7-4 选择-合法日期.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int y, m, d;
|
||||
|
||||
scanf("%4d/%2d/%2d", &y, &m, &d);
|
||||
|
||||
if (m < 1 || m > 12 || d < 1) {
|
||||
printf("No\n");
|
||||
} else if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
|
||||
if (d <= 31) {
|
||||
printf("Yes\n");
|
||||
} else {
|
||||
printf("No\n");
|
||||
}
|
||||
} else if (m == 2) {
|
||||
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) {
|
||||
if (d <= 29) {
|
||||
printf("Yes\n");
|
||||
} else {
|
||||
printf("No\n");
|
||||
}
|
||||
} else {
|
||||
if (d <= 28) {
|
||||
printf("Yes\n");
|
||||
} else {
|
||||
printf("No\n");
|
||||
}
|
||||
}
|
||||
} else { // m == 4 || m == 6 || m == 9 || m == 11
|
||||
if (d <= 30) {
|
||||
printf("Yes\n");
|
||||
} else {
|
||||
printf("No\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】3.选择结构2/7-4 选择-合法日期.jpg
Normal file
BIN
【实践课内】3.选择结构2/7-4 选择-合法日期.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 267 KiB |
Loading…
Reference in New Issue
Block a user