提交记录 #464
提交时间:2024-12-09 16:21:47
语言:c
状态:Unaccepted
编译情况:编译成功
固定测试点#1:
固定测试点#2:
固定测试点#3:
固定测试点#4:
固定测试点#5:
固定测试点#6:
固定测试点#7:
附加测试点暂不可用
54【日期】车辆限行
#include <stdio.h>
#include <stdbool.h>
int daysDifference();
// 判断是否是闰年
bool isLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
// 获取某年某月的天数
int daysInMonth(int year, int month) {
switch (month) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
return 31;
case 4: case 6: case 9: case 11:
return 30;
case 2:
return isLeapYear(year) ? 29 : 28;
default:
return 0; // 不应该发生的情况
}
}
// 计算给定日期与2012年4月8日之间的天数差
int daysDifference(int year, int month, int day) {
// 2012年4月8日之前的天数
int daysBefore = 0,y,m;
for ( y = 2012; y < year; ++y) {
daysBefore += isLeapYear(y) ? 366 : 365;
}
for ( m = 4; m < month; ++m) {
daysBefore += daysInMonth(year, m);
}
daysBefore += day - 8;
// 如果给定日期在2012年4月8日之前,则结果为负数
if (year < 2012 || (year == 2012 && (month < 4 || (month == 4 && day < 8)))) {
return -daysBefore;
}
return daysBefore;
}
void calculateRestriction(int daysDiff) {
int weekDayIndex = (daysDiff + 7) % 7;
char restrictions[7][100] = {"Free.", "1 and 6.", "2 and 7.", "3 and 8.", "4 and 9.", "5 and 0.", "Free."};
printf("%s\n", restrictions[weekDayIndex]);
}
int main() {
int year, month, day;
scanf("%d %d %d", &year, &month, &day);
int dd = daysDifference(year, month, day);
calculateRestriction((dd + 1) % 7); // 加1是因为从0开始计数
return 0;
}