博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDUOJ Calendar
阅读量:7183 次
发布时间:2019-06-29

本文共 2717 字,大约阅读时间需要 9 分钟。

Calendar
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 9036   Accepted: 3390

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.

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.

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
View Code
1 #include
2 #include
3 int shu1[13]={
31,28,31,30,31,30,31,31,30,31,30,32}; 4 int shu2[12]={
31,29,31,30,31,30,31,31,30,31,30,32}; 5 char str[8][15]={
"Monday","Tuesday","Wednesday" ,"Thursday","Friday","Saturday","Sunday"}; 6 int leap(int year) 7 { 8 9 if((year%400==0)||((year%4==0)&&(year%100!=0)))10 return 1;11 return 0;12 }13 int main()14 {15 int n,i,mon,year,yearday,k,day;16 while(scanf("%d",&n)&&(n!=-1))17 { 18 k=(n+5)%7;19 n=n+1;20 year=2000;mon=1;21 yearday=leap(year)?366:365;22 while(n>yearday)23 {24 n-=yearday;25 year++;26 yearday=leap(year)?366:365;27 //printf("n==%d",n);//28 }29 if(leap(year))30 { i=0;31 while(n>shu2[i])32 {
//printf("mon=%d",mon);//33 mon++;34 35 n-=shu2[i];36 i++;37 // printf("n=%d,i=%d\n",n,i);38 }39 }40 else 41 { i=0;42 while(n>shu1[i])43 {44 mon++;45 n-=shu1[i];46 i++;47 }48 }49 50 day=n;51 printf("%4d-%02d-%02d %s\n",year,mon,day,str[k]);52 }53 return 0;54 }55

转载地址:http://uwykm.baihongyu.com/

你可能感兴趣的文章
docker部署kafka(一)
查看>>
wordpress学习笔记 --(1)安装
查看>>
ORACLE PL/SQL编程之把游标说透
查看>>
splay树 1285 宠物收养所
查看>>
企业中squid+iptables多模块的综合应用案例
查看>>
Log4j 只输出某个包的日志
查看>>
树状数组 区间update/query
查看>>
同步手绘板——二维码验证登录
查看>>
PIX v2版本中Query 失败时, ERR段的构造
查看>>
我的友情链接
查看>>
1.4WEB API 路由配置及参数传输
查看>>
半透明遮罩层覆盖整个可视区域
查看>>
SpringMVC工作原理
查看>>
Linux防火墙(iptables )的功能详解二
查看>>
myeclipse常用快捷键和小技巧
查看>>
【Linux命令详解】10、查看历史命令—[ history]
查看>>
javascript判断一个元素是另一个元素的子元素
查看>>
小组项目第二周总结
查看>>
TC多台机器 License 问题
查看>>
图:国行HTC 8X修改市场区域
查看>>