# 蓝桥杯 ALGO-105 黑色星期五（日期）

【思路】：和CCF的一个题目差不多，先算天数，根据天数算星期。

【AC代码】：

`#include <iostream>#include <algorithm>#include <string>#include <cstdio>#include <cstring>using namespace std;int isLeapYear(int year){if (((0 == year%4) && (0 != year%100)) || (0 == year%400))return 1;return 0;}int getDayOfEarlyYear(int year){int i = 0;int sum_day = 0;for (i = 1998; i < year; i++){if (isLeapYear(i))sum_day += 366;elsesum_day += 365;}return sum_day;}int getDayOfMonth(int month, int year){int i = 0;int sum_day = 0;for (i = 1; i < month; i++){switch(i){case 1:case 3:case 5:case 7:case 8:case 10:case 12:sum_day += 31;break;case 4:case 6:case 9:case 11:sum_day += 30;break;case 2:if (isLeapYear(year))sum_day += 29;elsesum_day += 28;break;}}return sum_day;} int main(){//freopen("in.txt", "r", stdin);int y = 0, sum_day = 0, cnt = 0, i = 0;cin >> y;//加上前几年的天数sum_day += getDayOfEarlyYear(y);//判断每个月的13号 for (i = 1; i <= 12; i++){int temp = sum_day + getDayOfMonth(i, y) + 13;int w = ((temp%7)+4)%7-1;if (5 == w)cnt++;}//outputcout << cnt; return 0;}`

1 0