1
0
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:
Baoshuo Ren 2024-10-23 10:25:07 +08:00
parent 6896ba08ed
commit 004727e0d3
Failed to extract signature
8 changed files with 141 additions and 0 deletions

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 KiB