提交记录 #462
提交时间:2024-12-09 16:17:11
语言:c
状态:Unaccepted
编译情况:编译成功
固定测试点#1:
固定测试点#2:
固定测试点#3:
固定测试点#4:
固定测试点#5:
固定测试点#6:
固定测试点#7:
额外测试点#2:
54【日期】车辆限行
#include <stdio.h>
int leap_year(int year) {
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
int year_days(int year) {
return leap_year(year) ? 366 : 365;
}
int days(int year, int month, int day) {
int months[13] = {0, 31, leap_year(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int i;
for (i = 1; i < month; i++) {
day += months[i];
}
return day;
}
int jisuan(int y2, int m2, int d2) {
int y1 = 2012, m1 = 4, d1 = 8;
int day1 = days(y1, m1, d1);
int day2 = days(y2, m2, d2);
int re = 0;
int yearsDiff = y2 - y1;
if (yearsDiff == 0) {
re = day2 - day1;
} else {
for (int i = y1; i < y2; i++) {
int daysInYear = year_days(i);
if (i == y1) {
re += daysInYear - day1; // 从4月8日开始计算剩余天数
} else if (i == y2 - 1) {
re += day2;
} else {
re += daysInYear;
}
}
}
if(y2>2100)
re--;
return re;
}
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 = jisuan(year, month, day);
calculateRestriction((dd + 1) % 7); // 加1是因为从0开始计数
return 0;
}