题目1186:打印日期

点击打开链接

/*
	时间: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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值