POJ
来源:互联网 发布:剑灵女咒术师捏脸数据 编辑:程序博客网 时间:2024/06/14 15:35
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
Source
Shanghai 2004 Preliminary
题意:求在2000-1-1 n天后的日期
2000-1-1是星期六
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){ char s[10][20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; int mm[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; int day,y,m; while(cin>>day) { y = 2000,m = 1; if(day==-1) break; day++;//要求的是2000-1-1 day天,就是不包含第一天,所以要 +1 int xq = (5 + day % 7) % 7;//星期是七天一周期,比较好求 while(day>=366)//判断剩余的天数是否大于今年的总天数,若小于则开始求月份 { if(day-365==0) break; if((y%4==0&&y%100!=0)||y%400==0) { if(day-366==0) break; day--; } day -= 365; y++; } if((y%4==0&&y%100!=0)||y%400==0)//闰年二月份29天 mm[2]++; for(;m<=12;m++) { if(day-mm[m]<=0)//若剩余天数比该月总天数小或相等,则其月份就确定了 break; day-=mm[m]; } printf("%d-%02d-%02d %s\n",y,m,day,s[xq]); mm[2] = 28; } return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- 16.odoo入门——初探后台启动过程(三)
- 利用canvas下载图片,透明区默认变为黑色
- 快速了解微信小程序的使用,一个根据小程序的框架开发的todos app
- 在使用dedecms的channel标签来调子栏目的时候,指定 “type=son typeid=x” 发现currentstyle无效
- 泛型: 泛型的内部原理:类型擦除以及类型擦除带来的问题
- POJ
- 从setTimeout说事件循环模型
- Android开发 第10课 FrameLayout
- Corn Fields POJ
- Device-Dependent Bitmaps (DDB) 设备相关位图
- LeetCode 16. 3Sum Closest
- Redis 集群
- Linux grep命令
- Java使用ObjectOutputStream和ObjectInputStream序列号对象报java.io.EOFException异常的解决方法