题目描述
给出年分m和一年中的第n天,算出第n天是几月几号。
输入描述:
输入包括两个整数y(1<=y<=3000),n(1<=n<=366)。
输出描述:
可能有多组测试数据,对于每组数据, 按 yyyy-mm-dd的格式将输入中对应的日期打印出来。
示例1
输入
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
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 int main() 7 { 8 bool flag=false; 9 int a[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; 10 int b[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 11 int y,day; 12 int count; 13 while(cin>>y>>day) 14 { 15 flag=false; 16 count=0; 17 if((y%4==0&&y%100!=0)||(y%400==0)) flag=true; 18 if (flag==true) 19 while(day>a[count]) day-=a[count++]; 20 else 21 while(day>b[count]) day-=b[count++]; 22 printf("%04d-%02d-%02d ",y,count,day); 23 } 24 return 0; 25 }