zoukankan      html  css  js  c++  java
  • 完全相同的两年

    codeforces    B. The Same Calendar

    The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.

    The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.

    Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (https://en.wikipedia.org/wiki/Leap_year).

    Input

    The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.

    Output

    Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.

     
    Examples
      input
      2016
      output
      2044

      input
      2000
      output
      2028
     
      input
      50501
      output
      50507

    小析:求解出与给出年份完全相同的下一年,不仅需要平闰相同,还需要星期相同,
    2018年12月1号 星期六

    2019年12月1号 星期日
    2020年12月1号 星期二(闰年)

     1 def is_leap(year):
     2     if (year % 400 == 0 or year % 4 == 0 and year % 100 != 0):
     3         return 1
     4     else:
     5         return 0
     6 
     7 
     8 if __name__ == '__main__':
     9     year = 0
    10     try:
    11         year = int(input())
    12     except:
    13         exit(0)
    14     sum = 0
    15     next_year = year + 1
    16     while True:
    17         if is_leap(next_year) == 0:
    18             sum += 1
    19         else:
    20             sum += 2
    21         if (sum % 7 == 0) and (is_leap(year) == is_leap(next_year)):
    22             print(next_year)
    23             break
    24         else:
    25             next_year += 1
    View Code



  • 相关阅读:
    第六次作业
    第五次作业
    第四次作业
    第三次作业
    第二次作业 计科一班程晨
    第一次作业 计科一班程晨
    第七次作业
    第五次作业
    第四次作业
    第三次作业
  • 原文地址:https://www.cnblogs.com/z-712/p/12056885.html
Copyright © 2011-2022 走看看