九度oj 1186 打印日期

来源:

2003-2005年华中科技大学计算机研究生机试真题


#include <iostream>
#include<cstdio>
using namespace std;
#define isyear(x) (x%4==0&&x%100!=0||x%400==0?1:0)
int dayofmonth[13][2]={
    0,0,
    31,31,
    28,29,
    31,31,
    30,30,
    31,31,
    30,30,
    31,31,
    31,31,
    30,30,
    31,31,
    30,30,
    31,31
};
struct Date{
    int Year;
    int Month;
    int Day;
    void nextDay(){
        ++Day;
        if(Day>dayofmonth[Month][isyear(Year)]){
            Day=1;
            ++Month;
            if(Month>12){
                ++Year;
                Month=1;
            }
        }
    }
};
int buf[3002][13][32];
int main()
{
    Date tmp;
    tmp.Year=0;
    tmp.Month=1;
    tmp.Day=1;
    int cnt=0;
    while(tmp.Year!=3001){
        buf[tmp.Year][tmp.Month][tmp.Day]=cnt;
        cnt++;
        tmp.nextDay();
    }
    int y,n;
    Date ls;
    while(cin>>y>>n){
        ls.Year=y;ls.Month=1;ls.Day=1;
        for(int i=1;i<n;++i){
            ls.nextDay();
        }
        printf("%04d-%02d-%02d\n",ls.Year,ls.Month,ls.Day);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值