http://acm.fzu.edu.cn/problem.php?pid=2014
好办法!
View Code
#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 ;
}