poj
来源:互联网 发布:淘宝买的组装机怎么样 编辑:程序博客网 时间:2024/06/07 06:18
Calendar
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 13967 Accepted: 4951
Description
A calendar is a system for measuring time, from hours and minutes, to months and days, and finally to years and centuries. The terms of hour, day, month, year and century are all units of time measurements of a calender system.
According to the Gregorian calendar, which is the civil calendar in use today, years evenly divisible by 4 are leap years, with the exception of centurial years that are not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100 are not leap years, but 1600, 2000, and 2400 are leap years.
Given the number of days that have elapsed since January 1, 2000 A.D, your mission is to find the date and the day of the week.
According to the Gregorian calendar, which is the civil calendar in use today, years evenly divisible by 4 are leap years, with the exception of centurial years that are not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100 are not leap years, but 1600, 2000, and 2400 are leap years.
Given the number of days that have elapsed since January 1, 2000 A.D, your mission is to find the date and the day of the week.
Input
The input consists of lines each containing a positive integer, which is the number of days that have elapsed since January 1, 2000 A.D. The last line contains an integer −1, which should not be processed.
You may assume that the resulting date won’t be after the year 9999.
You may assume that the resulting date won’t be after the year 9999.
Output
For each test case, output one line containing the date and the day of the week in the format of "YYYY-MM-DD DayOfWeek", where "DayOfWeek" must be one of "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" and "Saturday".
Sample Input
1730174017501751-1
Sample Output
2004-09-26 Sunday2004-10-06 Wednesday2004-10-16 Saturday2004-10-17 Sunday
题意:从2000年1月1日开始之后的第几天为几年几月几日,周几。
思路:这题就直接模拟,从年份开始,闰年就加366,平年加365,然后超过就直接跳出,然后找出月份,最后就是日期了。
代码:
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int a[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};int check(int i){ if(i%400==0||(i%4==0&&i%100!=0)) return 1; else return 0;}int main(){ long long int n; while(cin>>n) { if(n==-1)break; int m=n; n++; int ans=0; int i,j; for(i=2000;;i++) { if(check(i)) ans+=366; else ans+=365; if(ans>=n)break; } if(check(i))ans-=366; else ans-=365; int g=n-ans; int y=i; int sum=0; for(j=1;;j++) { sum+=a[j]; if(check(i)&&j==2) sum++; if(sum>=g) break; } sum-=a[j]; if(check(i)&&j==2) sum--; int mm=g-sum; cout<<y<<"-"; if(j<10) { cout<<0<<j<<"-"; } else cout<<j<<"-"; if(mm<10) { cout<<0<<mm<<' '; } else cout<<mm<<' '; if(m%7==1) { cout<<"Sunday"; } else if(m%7==2) { cout<<"Monday"; } else if(m%7==3) { cout<<"Tuesday"; } else if(m%7==4) { cout<<"Wednesday"; } else if(m%7==5) { cout<<"Thursday"; } else if(m%7==6) { cout<<"Friday"; } else cout<<"Saturday"; cout<<endl; } return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- Linux下C++获得文件夹下的文件名
- [golang]函数用例
- Spring Boot的启动器Starter详解
- POJ
- Join操作基本:外连接、自然连接、内连接
- poj
- HDU 6078 Wavel Sequence
- mybatis 中的 jdbcType与javaType的对应关系
- 框架学习系列 mybatis 第十二篇 mapper映射文件之输出映射
- VIM中的保存和退出
- 快排方法代码记录
- (或许可以出题?
- 菜单显示
- Ubuntu下使用make编译c文件,不能调用sin cos 等函数问题的解决