-
[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;
}