diff --git a/【实践课内】3.选择结构2/7-1 选择-星期.c b/【实践课内】3.选择结构2/7-1 选择-星期.c new file mode 100644 index 0000000..76a0659 --- /dev/null +++ b/【实践课内】3.选择结构2/7-1 选择-星期.c @@ -0,0 +1,29 @@ +#include + +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; +} diff --git a/【实践课内】3.选择结构2/7-1 选择-星期.jpg b/【实践课内】3.选择结构2/7-1 选择-星期.jpg new file mode 100644 index 0000000..f8bfe87 Binary files /dev/null and b/【实践课内】3.选择结构2/7-1 选择-星期.jpg differ diff --git a/【实践课内】3.选择结构2/7-2 21选择-我们是冠军.c b/【实践课内】3.选择结构2/7-2 21选择-我们是冠军.c new file mode 100644 index 0000000..058a162 --- /dev/null +++ b/【实践课内】3.选择结构2/7-2 21选择-我们是冠军.c @@ -0,0 +1,52 @@ +#include + +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; +} diff --git a/【实践课内】3.选择结构2/7-2 21选择-我们是冠军.jpg b/【实践课内】3.选择结构2/7-2 21选择-我们是冠军.jpg new file mode 100644 index 0000000..c14c6a1 Binary files /dev/null and b/【实践课内】3.选择结构2/7-2 21选择-我们是冠军.jpg differ diff --git a/【实践课内】3.选择结构2/7-3 21选择-盘闰年.c b/【实践课内】3.选择结构2/7-3 21选择-盘闰年.c new file mode 100644 index 0000000..3821de4 --- /dev/null +++ b/【实践课内】3.选择结构2/7-3 21选择-盘闰年.c @@ -0,0 +1,21 @@ +#include + +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; +} diff --git a/【实践课内】3.选择结构2/7-3 21选择-盘闰年.jpg b/【实践课内】3.选择结构2/7-3 21选择-盘闰年.jpg new file mode 100644 index 0000000..c808fc6 Binary files /dev/null and b/【实践课内】3.选择结构2/7-3 21选择-盘闰年.jpg differ diff --git a/【实践课内】3.选择结构2/7-4 选择-合法日期.c b/【实践课内】3.选择结构2/7-4 选择-合法日期.c new file mode 100644 index 0000000..8ca0ca8 --- /dev/null +++ b/【实践课内】3.选择结构2/7-4 选择-合法日期.c @@ -0,0 +1,39 @@ +#include + +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; +} diff --git a/【实践课内】3.选择结构2/7-4 选择-合法日期.jpg b/【实践课内】3.选择结构2/7-4 选择-合法日期.jpg new file mode 100644 index 0000000..62889ab Binary files /dev/null and b/【实践课内】3.选择结构2/7-4 选择-合法日期.jpg differ