解题思路:
就是从19981月1号的星期四一直往下数,星期 5,6,7,然后循环一个星期,从星期一开始继续数
注意事项:是那一年有多少个,不是累加的....我看错题,交了三次错了,就是算了累加的次数.......
参考代码:
int n; cin >> n;//年份 int two = 0; int week = 4, sum = 0; for (int i = 1998; i <= n; i++){ if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)two = 1;//判断闰年 else two = 0; for (int month = 1; month <= 12; month++){ int monthday = 0; switch (month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: monthday = 31; break; case 4: case 6: case 9: case 11: monthday = 30; break; case 2: if (two)monthday = 29; else monthday = 28; break; } for (int j = 1; j <= monthday; j++){ if (i == n&&(j == 13 && week == 5))sum++;//在第n年菜开始计算黑色星期五 week++; if (week == 8)week = 1; } } } cout <<sum << endl;
0.0分
2 人评分