Codeforces

 Checking the Calendar

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: 312831303130313130313031.

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)

1.以上为题目原题,由于我英文水平太差,读题就耗费了我一些时间!终于大概知道了题意,题意为:

给你一周中的两个时间,如周一,周二,让你写个程序判断一下存不存在让周一为某一平年的某一个月的第一天,而周二恰好为下个月的第一天。并且是在同一年内。如果存在则输出YES,否则输出NO。

2。解题思路:我们可以从第一个月开始判断,逐一递推到十一月。

3.参考代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
   char s1[15],s2[15];
   char s[7][15]={"monday","tuesday","wednesday","thursday","friday","saturday","sunday"};
   int a[]={31,28,31,30,31,30,31,31,30,31,30,31};
   int i,k,m;
   cin>>s1>>s2;
   for(i=0;i<7;i++)
   {
   	if(strcmp(s[i],s1)==0)
   	{
   		k=i+1;
	   }
	   if(strcmp(s[i],s2)==0)
	   {
	   	m=i+1;
	   }
   }
int flag=0,temp,p;
   for(i=0;i<11;i++)
   {
     temp=a[i]%7;
     if(k+temp==7)
     {
     	p=k+temp;
	 }
	 else
	 {
	 	p=(k+temp)%7;
	 }
     if(p==m)
       {   cout<<"YES"<<endl;
           flag=1;
            break;}
    }
if(flag==0)
  cout<<"NO"<<endl;
return 0;
}
4.本题应注意的问题:

(1)字符串是不能直接比较的,进行字符串比较应调用相应的函数strcmp()。

(2)(k+temp)%7应注意当(k+temp)等于7时则不应该进行求余运算,否则将导致错误的结果。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值