You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: “monday”, “tuesday”, “wednesday”, “thursday”, “friday”, “saturday”, “sunday”.
Input
The input consists of two lines, each of them containing the name of exactly one day of the week. It’s guaranteed that each string in the input is from the set “monday”, “tuesday”, “wednesday”, “thursday”, “friday”, “saturday”, “sunday”.
Output
Print “YES” (without quotes) if such situation is possible during some non-leap year. Otherwise, print “NO” (without quotes).
Examples
input
monday
tuesday
output
NO
input
sunday
sunday
output
YES
input
saturday
tuesday
output
YES
Note
In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday.
给出两个星期,问是不是年的连续月,只定义一年31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.这么多天。。
给星期一个值0-6,那么(a+31%7)==b||(a+30%7)==b||(a+28%7)==b才满足
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<set>
using namespace std;
#define pi acos(-1.0)
#define EPS 1e-6 //log(x)
#define e exp(1.0); //2.718281828
#define mod 1000000007
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
typedef long long LL;
#define debug(x) cout<<x<<endl;
#define debug2(x) cout<<x<<" ";
int m[22]={0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
char A[10],B[10];
int a,b;
scanf("%s",&A);
scanf("%s",&B);
if(strcmp(A,"monday")==0) a=1;
if(strcmp(A,"tuesday")==0) a=2;
if(strcmp(A,"wednesday")==0) a=3;
if(strcmp(A,"thursday")==0) a=4;
if(strcmp(A,"friday")==0) a=5;
if(strcmp(A,"saturday")==0) a=6;
if(strcmp(A,"sunday")==0) a=0;
if(strcmp(B,"monday")==0) b=1;
if(strcmp(B,"tuesday")==0) b=2;
if(strcmp(B,"wednesday")==0) b=3;
if(strcmp(B,"thursday")==0) b=4;
if(strcmp(B,"friday")==0) b=5;
if(strcmp(B,"saturday")==0) b=6;
if(strcmp(B,"sunday")==0) b=0;
bool ok=false;
for(int i=1;i<=12;i++){
int day=m[i];
if((a+day%7)%7==b) ok=true;
}
if(ok) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I have a dream!A AC deram!!
orz orz orz orz orz orz orz orz orz orz orz
orz orz orz orz orz orz orz orz orz orz orz
orz orz orz orz orz orz orz orz orz orz orz
*/