poj2080!【水题】
来源:互联网 发布:舔女生尿道口 知乎 编辑:程序博客网 时间:2024/05/17 04:30
/*CalendarTime Limit: 1000MS Memory Limit: 30000K Total Submissions: 11251 Accepted: 4160 DescriptionA 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.InputThe 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 <span style="color:#ff0000;">date won’t be after the year 9999.</span>OutputFor 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 Input1730174017501751-1Sample Output2004-09-26 Sunday2004-10-06 Wednesday2004-10-16 Saturday2004-10-17 SundaySourceShanghai 2004 Preliminary*/#include<stdio.h>#include<string.h>int leap(int x){if( (x%400 == 0) || ( x % 100 != 0 && x % 4 == 0))return 1;return 0;}int main(){ int a[9000], i, j = 0, n, b[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; for(i = 2000; i < 10010; i++) if(leap(i)) a[j++] = 366; else a[j++] = 365;int year, mon, day;char week[10]; while(scanf("%d", &n) != EOF) {if(n == -1)break;year = 2000;mon = 1;switch ((n-1) % 7){case 0:strcpy(week, "Sunday");break;case 1:strcpy(week, "Monday");break;case 2:strcpy(week, "Tuesday");break;case 3:strcpy(week, "Wednesday");break;case 4:strcpy(week, "Thursday");break;case 5:strcpy(week, "Friday");break;case 6:strcpy(week, "Saturday");break;}for(i = 0; i < 9000; i++)if(n >= a[i])//大于等于{n -= a[i];year++;}elsebreak;for(i = 0; i < 12; i++){if(i == 1 ){if(leap(year)){if(n >= b[i]+1)//大于等于{n -= (b[i]+1);mon++;}elsebreak;}else{if(n >= b[i])//大于等于{n -= b[i];mon++;}elsebreak;}}else{if(n >= b[i])//大于等于{n -= b[i];mon++;}elsebreak;}}day = n+1;if(mon > 9 && day > 9)printf("%d-%d-%d %s\n", year, mon, day, week);else if( mon > 9 && day < 10)printf("%d-%d-0%d %s\n", year, mon, day, week);else if(mon < 10 && day > 9)printf("%d-0%d-%d %s\n", year, mon, day, week);elseprintf("%d-0%d-0%d %s\n", year, mon, day, week);}return 0;}
从2000-01-01开始,给定一个天数,求出年月日和星期几。
难点在于边界判断,年和月的边界要大于等于才行,不然一直wa。
题目还要求年数不会超过9999.......
0 0
- poj2080!【水题】
- poj2080
- POJ2080
- poj2080
- poj2080
- poj2080
- POJ2080-Calendar
- POJ2080-Calendar
- poj2080 日历
- poj2080 Calendar
- poj2080 Calendar
- poj2080(日期处理问题)
- POJ2080日历问题
- POJ2080解题报告
- POJ2080简单模拟
- poj2080--算日期
- POJ2080--Calendar以及一个类似的编程面试题
- POJ2080 日期计算(1),模拟题,因为细节WA很久
- 石子合并
- POJ3332 Parsing Real Numbers DFA
- 无线路由不能上网问题的解决办法
- Flume SimpleAsyncHbaseEventSerializer 类解析
- 简化版的LDA源码
- poj2080!【水题】
- 从先序遍历和中序遍历重建二叉树
- 再试一下,看是否好用
- poj 2594 二分图 Floyd闭包+最小路径覆盖
- Dom解析XML文件具体用法
- poj 2029 (暴力枚举)水题
- 操作系统虚拟化底层基础之命名空间(namespace)
- 51416/D辛苦屎了,骗纸呐o o
- 网页设计用目标的好处