Day of Week
2018-03-13 08:56
232 查看
题目描述
We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400. For example, years 2004, 2180 and 2400 are leap. Years 2004, 2181 and 2300 are not leap. Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today’s agreement about dating.输入描述:
There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.
输出描述:
Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case. Month and Week name in Input/Output: January, February, March, April, May, June, July, August, September, October, November, December Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
#include<stdio.h> #include<string.h> #define ISLEAP(x) x%100!=0 && x%4==0 || x%400==0 ? 1 : 0 struct date{ int day; int month; int year; }; int dayOfMonth[13][2]={ 0,0, 31,31, 28,29, 31,31, 30,30, 31,31, 30,30, 31,31, 31,31, 30,30, 31,31, 30,30, 31,31 }; void nextDay(struct date * d){ d->day++; if(d->day > dayOfMonth[d->month][ISLEAP(d->year)]){ d->day = 1; d->month++; if(d->month > 12){ d->month = 1; d->year++; } } } int abs(int x){ return x>0 ? x:-x; } int buf[3001][13][32]; char monthName[13][20]={ "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; char weekName[7][20]={ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", }; int main(){ struct date * d = NULL; struct date temp; int day,month,year; char mName[20]; int i; int cnt; int days; d = &temp; d->day = 1; d->month = 1; d->year = 1000; cnt = 0; while(d->year < 3001){ buf[d->year][d->month][d->day] = cnt; cnt++; nextDay(d); } while(scanf("%d %s %4d",&day,&mName,&year)!=EOF){ for( i=1; i<13; i++ ){ if(strcmp(mName,monthName[i])==0) month = i; } days = abs(buf[2018][3][13]-buf[year][month][day]); days %= 7; printf("%s\n",weekName[(days+2)%7]); } return 0; }
相关文章推荐
- 简单准确理解Calendar.DAY_OF_WEEK
- '?' can only be specfied for Day-of-Month -OR- Day-of-Week.
- Linux crontab 的 day_of_month 和 day_of_week
- android calendar DAY_OF_WEEK_IN_MONTH
- jobdu 7 Day of Week
- Linux crontab 的 day_of_month 和 day_of_week
- java中Calendar.DAY_OF_WEEK需要减一的原因
- java 中的calendar.DAY_OF_WEEK – 1 的原因
- [日期类问题] 例 2.4 Day of week(九度教程第 7 题)
- Linux crontab 的 day_of_month 和 day_of_week
- mysql时间函数之dayofweek,dayofmonth,dayofyear,weekofyear用法
- 题目7:Day of Week
- Day of Week
- RPG ILE Day of Week
- Linux crontab 的 day_of_month 和 day_of_week
- java的Calendar,获取月份少一月的问题及其它注意事项day_of_week()函数:
- 题目7:Day of Week
- How to Get First and Last Day of a Week in SQL Server
- Java中Calendar.DAY_OF_WEEK需要减一的原因
- 关于ORACLE ORA-01846: not a valid day of the week 错误的解决办法