zoukankan      html  css  js  c++  java
  • Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar 水题

    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");
    }
  • 相关阅读:
    100道MySQL数据库经典面试题解析(收藏版)
    input()函数的进阶用法
    MySQL数据库面试题(2020最新版)
    mysql 1418错误_MySQL 错误1418 的原因分析及解决方法
    使用pymysql循环删除重复数据,并修改自增字段偏移值
    字典get方法和setdesault方法,统计message中各元素的出现频次
    Python中字典get方法的使用技巧
    collections模块
    python的30个编程技巧
    SQL中where与having的区别
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5941776.html
Copyright © 2011-2022 走看看