http://acm.fzu.edu.cn/problem.php?pid=2014
好办法!
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include
"
iostream
"
using namespace std;
int today[] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
bool L_y( int year)
{
if (year % 4 == 0 && year % 100 || year % 400 == 0 ) return true ;
return false ;
}
int main()
{
int n;
while (scanf( " %d " , & n) != EOF)
{
int year = 2012 ,month = 12 ,day = 21 ;
while (n -- )
{
day -- ;
if (day == 0 )
{
month -- ;
if (month == 0 )
{
year -- ;
month = 12 ;
}
day = today[month];
if ((L_y(year)) && (month == 2 )) // 判断是否是闰年
{
day = 29 ;
}
}
}
printf( " %4d-%02d-%02d\n " ,year,month,day);
}
return 0 ;
}
using namespace std;
int today[] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
bool L_y( int year)
{
if (year % 4 == 0 && year % 100 || year % 400 == 0 ) return true ;
return false ;
}
int main()
{
int n;
while (scanf( " %d " , & n) != EOF)
{
int year = 2012 ,month = 12 ,day = 21 ;
while (n -- )
{
day -- ;
if (day == 0 )
{
month -- ;
if (month == 0 )
{
year -- ;
month = 12 ;
}
day = today[month];
if ((L_y(year)) && (month == 2 )) // 判断是否是闰年
{
day = 29 ;
}
}
}
printf( " %4d-%02d-%02d\n " ,year,month,day);
}
return 0 ;
}