点击打开链接
/*
时间:2013.2.1
目的:题目1186:打印日期http://ac.jobdu.com/problem.php?pid=1186
*/
#include <stdio.h>
int Month[13] = {13,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int year, day, i;
int ye[4],yu[2],da[2];//设四个值,为了格式化输出ye为年,yu为月,da为天
while(~scanf("%d%d", &year, &day))
{
ye[0] = ye[1] = ye[2] = ye[3]= yu[0] = yu[1] = da[0] = da[1]=0;
if((year%4==0&&year%100!=0)||year%400==0)
++Month[2]; //呼应
for(i=1;i<13;++i)
{
if(Month[i]<day)
day -= Month[i];
else
break;
}
Month[2] = 28;//注意此处一定要恢复与if出呼应
ye[3] = year%10;
ye[2] = year%100/10;
ye[1] = year/100%10;
ye[0] = year/1000;
yu[1] = i%10;
yu[0] = i/10;
da[1] = day%10;
da[0] = day/10;
printf("%d%d%d%d-%d%d-%d%d\n",ye[0],ye[1],ye[2],ye[3],yu[0],yu[1],da[0],da[1]);
}
return 0;
}
/*
--------------------
2000 3 思路:1.判断闰年
2000-01-03 2. 注意输出格式即可
2000 31
2000-01-31
2000 40
2000-02-09
2000 60
2000-02-29
2000 61
2000-03-01
2001 60
2001-03-01
--------------------
*/
#include <stdio.h>
int Month[13] = {13,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int year, day, i;
while(~scanf("%d%d", &year, &day))
{
if((year%4==0&&year%100!=0)||year%400==0)
++Month[2];
for(i=1;i<13;++i)
{
if(Month[i]<day)
day -= Month[i];
else
break;
}
Month[2] = 28;
printf("%04d-%02d-%02d\n",year,i,day);
}
return 0;
}