A. Checking the Calendar
题目连接:
http://codeforces.com/contest/724/problem/A
Description
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).
Sample Input
monday
tuesday
Sample Output
NO
Hint
题意
给你两个星期几,然后问你可不可能这个月的一号是第一个星期,下个月的一号是第二个星期。
题解:
暴力模拟就好了嘛
水题
代码
#include<bits/stdc++.h>
using namespace std;
int m[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31};
int getid(string s)
{
if(s[0]=='m')return 0;
if(s[0]=='t'&&s[1]=='u')return 1;
if(s[0]=='w')return 2;
if(s[0]=='t'&&s[1]=='h')return 3;
if(s[0]=='f')return 4;
if(s[0]=='s'&&s[1]=='a')return 5;
if(s[0]=='s')return 6;
}
string s1,s2;
int main()
{
cin>>s1>>s2;
int p=getid(s1),q=getid(s2);
for(int i=0;i<7;i++)
{
int now=i;
for(int j=0;j<12;j++)
{
for(int k=0;k<m[j];k++)
{
now=(now+1)%7;
if(k==0&&now==p&&(now+m[j])%7==q)
return puts("YES");
}
}
}
printf("NO");
}