#include <stdio.h>
#include <string.h>// 判断是否为闰年
int isLeapYear(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}// 计算指定年份黑色星期五数量并列出具体日期
void GetYearBlackFriday(int year) {int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};char *months[12] = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};if (isLeapYear(year)) {days[1] = 29;}int count = 0;int totalDays = 0;// 计算从1900年到指定年份前一年的总天数for (int y = 1900; y < year; y++) {if (isLeapYear(y)) {totalDays += 366;} else {totalDays += 365;}}printf("%d年的黑色星期五日期如下:\n", year);for (int month = 0; month < 12; month++) {// 计算当前月份13号是星期几int weekday = (totalDays + 13) % 7;if (weekday == 5) {printf("%s 13日\n", months[month]);count++;}// 累加当前月份的天数totalDays += days[month];}printf("\n%d年共有%d个黑色星期五\n", year, count);
}int main() {int year;while (1) {printf("请输入年份(输入0退出):");scanf("%d", &year);if (year == 0) {break;}if (year < 1900) {printf("年份必须大于等于1900\n");continue;}GetYearBlackFriday(year);}return 0;
}