【Algothrim】节日

来源:互联网 发布:node.js makefile 编辑:程序博客网 时间:2024/04/30 22:14


Description

  有一类节日的日期并不是固定的,而是以“a月的第b个星期c”的形式定下来的,比如说母亲节就定为每年的五月的第二个星期日。  现在,给你a,b,c和y1, y2(1850 ≤ y1, y2 ≤ 2050),希望你输出从公元y1年到公元y2年间的每年的a月的第b个星期c的日期。  提示:关于闰年的规则:年份是400的整数倍时是闰年,否则年份是4的倍数并且不是100的倍数时是闰年,其他年份都不是闰年。例如1900年就不是闰年,而2000年是闰年。

Input

  输入包含恰好一行,有五个整数a, b, c, y1, y2。其中c=1, 2, ……, 6, 7分别表示星期一、二、……、六、日。

评测用例规模与约定  所有评测用例都满足:1 ≤ a ≤ 12,1 ≤ b ≤ 5,1 ≤ c ≤ 7,1850 ≤ y1, y2 ≤ 2050。

Output

  对于y1和y2之间的每一个年份,包括y1和y2,按照年份从小到大的顺序输出一行。  如果该年的a月第b个星期c确实存在,则以"yyyy/mm/dd"的格式输出,即输出四位数的年份,两位数的月份,两位数的日期,中间用斜杠“/”分隔,位数不足时前补零。  如果该年的a月第b个星期c并不存在,则输出"none"(不包含双引号)。

Sample Input

5 2 7 2014 2015

Sample Output

2014/05/112015/05/10
#include<iostream>#include<stdio.h>using namespace std;int isleapyear(int year){if (!(year % 400) || ((year % 4 == 0) && (year % 100 != 0))){return 1;}return 0;}int GetDate(int year, int a, int b, int c){int i = 0;int date = 0;for ( i = 1970; i < year; i++){int days = isleapyear(i) ? 366 : 365;date = date + days;}int days = isleapyear(year) ? 29 : 28;switch (a){case 2:date = date + 31;break;case 3:date = date + 31 + days;break;case 4:date = date + 31 + days+31;break;case 5:date = date + 31 + days + 31 + 30;break;case 6:date = date + 31 + days + 31 + 30 + 31;break;case7:date = date + 31 + days + 31 + 30 + 31 + 30;break;case 8:date = date + 31 + days + 31 + 30 + 31 + 30 + 31;break;case 9:date = date + 31 + days + 31 + 30 + 31 + 30 + 31 + 31;break;case 10:date = date + 31 + days + 31 + 30 + 31 + 30 + 31 + 31 + 30;break;case 11:date = date + 31 + days + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;break;case 12:date = date + 31 + days + 31 + 30 + 31 + 30 + 31 + 31 + 30;break;default:break;}int week = date % 7;switch (week){case 0:week = 4;break;case 1:week = 5;break;case 2:week = 6;break;case 3:week = 7;break;case 4:week = 1;break;case 5:week =2;break;case 6:week = 3;break;default:break;}if (c ==  week){return 1+(b - 1) * 7;}else if (c>week){return 1+(c - week) + 7 * (b - 1);}else{return 1+(c - week) + 7 * (b);}}int main(){int a, b, c, y1, y2;cin >> a >> b >> c >> y1>> y2;if (y1>y2){int temp = y1;y1 = y2;y2 = temp;}int date1 = GetDate(y1, a, b, c);int date2 = GetDate(y2, a, b, c);if ((a == 2 && (date1 >(28 + isleapyear(y1))))||( (a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12) && date1 >31)|| ((a == 4 || a == 6 || a == 9 || a == 11) && date1 >30)){//cout << "none" << endl;printf("none\n");}else{//cout << y1 << "/" << a << "/" << date1 << endl;printf("%d/%02d/%02d\n",y1,a,date1);}if ((a == 2 && (date2 >(28 + isleapyear(y2))))|| ((a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12) && date2 >31)|| ((a == 4 || a == 6 || a == 9 || a == 11) && date2 >30)){//cout << "none" << endl;printf("none\n");}else{//cout << y2 << "/" << a << "/" << date2 << endl;printf("%d/%02d/%02d\n", y2, a, date2);}return 0;}
不知道为啥,答案显示wrong answer...
0 0