1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 15:48:42 +00:00
202401-programming-assignments/【实践课内】3.选择结构2/7-4 选择-合法日期.c

40 lines
893 B
C

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