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".
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".
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).
monday tuesday
NO
sunday sunday
YES
saturday tuesday
YES
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.
刚开始看到这道题的时候,感觉很难,然后就跳过去了,但是一队友让我给她翻译一下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.这句话是什么意思,然后我们俩一起就开始做起来了。
题目的意思就是能否找到一个平年的某两个连续的月份,满足那两个月份中的第一个月份的1号是你输入的第一个字符串所表示的星期几数,同时第二个月份的1号是输入的第二个字符串所表示的星期几数。
思路:因为是平年,所以每个月份之间相差的天数是确定的,对7取余,得到的分别为3,0,3,2,3,2,3,3,2,3,2.所以如果所输入的两个字符串之间相差的天数为0,2,3则输出YES,否则为NO。
第一次写博客,语言组织的可能不是很好,望见谅。
OK,下面上代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
char a[10],b[10];
scanf("%s",a);
scanf("%s",b);
int f,l;
if(strcmp(a,"monday")==0)
f=1;
if(strcmp(a,"tuesday")==0)
f=2;
if(strcmp(a,"wednesday")==0)
f=3;
if(strcmp(a,"thursday")==0)
f=4;
if(strcmp(a,"friday")==0)
f=5;
if(strcmp(a,"saturday")==0)
f=6;
if(strcmp(a,"sunday")==0)
f=7;
if(strcmp(b,"monday")==0)
l=1;
if(strcmp(b,"tuesday")==0)
l=2;
if(strcmp(b,"wednesday")==0)
l=3;
if(strcmp(b,"thursday")==0)
l=4;
if(strcmp(b,"friday")==0)
l=5;
if(strcmp(b,"saturday")==0)
l=6;
if(strcmp(b,"sunday")==0)
l=7;
int c;//两个字符串所表示的星期几的天数差
if(f>l)
c=7-f+l;
else
c=l-f;
if(c==0||c==2||c==3)
printf("YES\n");
else
printf("NO\n");
return 0;
}
752

被折叠的 条评论
为什么被折叠?



