- 题目描述:
-
给出年分m和一年中的第n天,算出第n天是几月几号。
- 输入:
-
输入包括两个整数y(1<=y<=3000),n(1<=n<=366)。
- 输出:
-
可能有多组测试数据,对于每组数据,
按 yyyy-mm-dd的格式将输入中对应的日期打印出来。
- 样例输入:
-
2000 3 2000 31 2000 40 2000 60 2000 61 2001 60
- 样例输出:
-
2000-01-03 2000-01-31 2000-02-09 2000-02-29 2000-03-01 2001-03-01
#include<stdio.h> #include<algorithm> #include<iostream> #include<stack> #include<vector> #include<string.h> #include<limits.h> #include<stdlib.h> #define ABS(x) ((x)>=0?(x):(-(x))) using namespace std; static int month[]={0,31,28,31,30,31,30,31,31,30,31,30}; int main() { freopen("test.in","r",stdin); freopen("test.out","w",stdout); int year,days; int i ; bool leap; while(cin>>year>>days) { if((year%4==0&&year%100!=0)||year%400==0) leap = true; else leap = false; for(i=1;i<12;i++) { if(i!=2) { if(days<=month[i]) break; else days -= month[i]; } else { if(leap) { if(days<=month[i]+1) break; else days = days - month[i] - 1; } else { if(days<=month[i]) break; else days -= month[i]; } } } printf("%04d-%02d-%02d ",year,i,days); } fclose(stdin); fclose(stdout); return 0; }