# codeup——问题 B: Day of Week（按照蔡勒公式写）

[提交][状态][讨论版][命题人:外部导入]

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.

21 December 2012
5 January 2013

Friday
Saturday

#include <stdio.h>
#include <iostream>
#include <string.h>

int month[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 } };
bool isleap(int year){//判断是否是闰年
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int change(char month[20]){//判断英文单词对应的月份的数字
int m;
if (month[0] == 'F') m = 14;
if (month[0] == 'S') m = 9;
if (month[0] == 'O') m = 10;
if (month[0] == 'N') m = 11;
if (month[0] == 'D') m = 12;
if (month[0] == 'M'){
if (month[2] == 'r') m = 3;
else m = 5;
}
if (month[0] == 'J'){
if (month[1] == 'a') m = 13;
else if (month[2] == 'n') m = 6;
else if (month[2]=='l') m = 7;
}
if (month[0] == 'A') {

if (month[2] == 'r') m = 4;
else m = 8;
}
return m;
}
int main(){
int d1, y1;
char cm1[20];
while (scanf("%d %s %d", &d1, cm1, &y1) != EOF){
int y=0, c=0, m=0, d=0,w=0;
m = change(cm1);

if (m > 12){
c = (y1-1) / 100;
y = (y1-1)%100;

}
else {
c = y1 / 100;
y = y1 % 100;

}

d = d1;

w = y + int(y / 4) + int(c / 4) - 2 * c + int((26 * (m + 1)) / 10) + d - 1;

int today=0;
while (w<0){

w = w + 7;
}

today = w % 7;

switch (today){
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
case 0:
printf("Sunday\n");

}
}
system("pause");//提交的时候要注销掉
return 0;
}