[1271] Nth Day is Which Day

  • [1271] Nth Day is Which Day

  • http://ac.nbutoj.com/Problem/view.xhtml?id=1271
  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • The first day is 1 year 1 month 1 day, so the Nth day is which day?
  • 输入
  • Input until EOF.   Input a positive integer N means the Nth day(0<N<365000).  
  • 输出
  • You should output the date of that day(year month day).  
  • 样例输入
  • 1
    2
    32
    
  • 样例输出
  • 1 1 1
    1 1 2
    1 2 1
    
  • 提示
  • 来源
  • hungar

 

#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int m1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int m2[12]={31,29,31,30,31,30,31,31,30,31,30,31};

int main(){

    //freopen("input.txt","r",stdin);

    int n;
    while(~scanf("%d",&n)){
        int year=1,month=1,day=n,p=0;
        if(day%146097==0){    //400年的天数:400*365+97
            day--;
            p++;
        }
        year+=day/146097*400;
        day%=146097;

        if(day%36524==0){     //100年的天数:100*365+24
            day--;
            p++;
        }
        year+=day/36524*100;
        day%=36524;

        if(day%1461==0){      //4年的天数: 4*365+1
            day--;
            p++;
        }
        year+=day/1461*4;
        day%=1461;

        if(day%365==0){
            day--;
            p++;
        }
        year+=day/365*1;
        day%=365;

        int i=0;
        if(year%400==0 || (year%4==0 && year%100!=0)){
            while(day>m2[i]){
                month++;
                day-=m2[i];
                i++;
            }
        }else{
            while(day>m1[i]){
                month++;
                day-=m1[i];
                i++;
            }
        }
        day+=p;
        printf("%d %d %d\n",year,month,day);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/jackge/archive/2013/03/14/2960218.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值