C语言问题 : Checking the Calendar

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int f(char *);
int main()
{
    int b[2], sum;
    sum = -1;
    char a[2][20];
    scanf("%s", a[0]);
    scanf("%s", a[1]);
    b[0] = f(a[0]);
    b[1] = f(a[1]);
    if(b[0] >= b[1])  sum = b[0] - b[1];
    else sum = b[1] - b[0];
    if(sum == 0 || sum == 2 || sum == 3)  printf("YES\n");
    else  printf("NO\n");
    return 0;
}
int f(char *a)
{
    int b;
    if     (strcmp(a, "monday"))     b = 1;
    else if(strcmp(a, "tuesday"))    b = 2;
    else if(strcmp(a, "wednesday"))  b = 3;
    else if(strcmp(a, "thursday"))   b = 4;
    else if(strcmp(a, "friday"))     b = 5;
    else if(strcmp(a, "saturday"))   b = 6;
    else if(strcmp(a, "sunday"))     b = 7;
    return b;
}

 代码提交是Wrong answer ,原因:

1. 下方函数的strcmp使用错误,当所比较的字符串相等时,其返回值为0,我误以为和if函数一样,相等时为1

2. sum的计算不能够只计算时间间隔,一个星期的两天可以有:从前面向后数和从后面向前面数两种方式,所以两天的间隔可能有两个结果,此处只能用后一天减前一天

改正代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int f(char *);
int main()
{
    int b[2], sum;
    sum = -1;
    char a[2][20];
    scanf("%s", a[0]);
    scanf("%s", a[1]);
    b[0] = f(a[0]);
    b[1] = f(a[1]);
    sum = b[1] - b[0];
    //计算后一天和前一天差几天,一定要用后一天减前一天!不要减反!!!
    if(sum < 0) sum += 7;//如果sum<0则进入下一个星期
    if(sum == 0 || sum == 2 || sum == 3)  printf("YES\n");
    //每个月有28或30或31天三种可能,相当于间隔0或2或3天,所以sum的三种结果符合要求
    else  printf("NO\n");
    return 0;
}
int f(char *a)
{
    int b;
    if     (strcmp(a, "monday") == 0)     b = 1;
    else if(strcmp(a, "tuesday") == 0)    b = 2;
    else if(strcmp(a, "wednesday") == 0)  b = 3;
    else if(strcmp(a, "thursday") == 0)   b = 4;
    else if(strcmp(a, "friday") == 0)     b = 5;
    else if(strcmp(a, "saturday") == 0)   b = 6;
    else if(strcmp(a, "sunday") == 0)     b = 7;
    return b;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这个问题通常是由于缺少必要的编译工具或环境变量设置不正确引起的。为了解决这个问题,我们需要进行以下步骤: 1. 检查编译工具是否已经安装 首先,我们需要检查系统上是否安装了必要的编译工具,例如gcc、make等。可以使用以下命令检查它们是否已经安装: ``` which gcc which make ``` 如果这些命令没有输出路径,则说明它们未安装或者没有在PATH环境变量中设置。在这种情况下,我们需要安装这些工具。对于Debian/Ubuntu等基于apt的发行版,可以使用以下命令安装: ``` sudo apt-get update sudo apt-get install build-essential ``` 2. 检查环境变量设置是否正确 如果已经安装了必要的编译工具,但是仍然遇到了这个错误,那么可能是环境变量设置不正确导致的。我们需要检查以下环境变量是否设置正确: - PATH:包含编译工具所在的路径 - LD_LIBRARY_PATH:包含库文件所在的路径 - C_INCLUDE_PATH:包含头文件所在的路径 可以使用以下命令检查它们的值是否正确: ``` echo $PATH echo $LD_LIBRARY_PATH echo $C_INCLUDE_PATH ``` 如果这些变量没有正确设置,我们需要手动设置它们。例如,对于bash shell,可以将以下命令添加到.bashrc文件中: ``` export PATH=$PATH:/usr/local/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include ``` 3. 检查config.log文件 如果上述步骤都没有解决问题,我们需要查看config.log文件来获取更详细的错误信息。可以使用以下命令查看config.log文件: ``` less /home/farsight/farsight/feng/day8/jpeg-9e/config.log ``` 在config.log文件中,可以查找类似于“error: C compiler cannot create executables”的错误信息,并查看更详细的错误描述。根据错误描述,我们可以进行进一步的排查和修复。 希望这些步骤可以帮助你解决问题

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值