zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 13 B. The Same Calendar 水题

    B. The Same Calendar

    题目连接:

    http://www.codeforces.com/contest/678/problem/B

    Description

    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.

    Sample Input

    2016

    Sample Output

    2044

    Hint

    题意

    给你一个年y,让你找到大于y的某一年,使得和y这一年的日期一模一样。

    题解:

    其实就是经过的天数%7==0

    而且那一年的平闰年和这一年是一样的。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    bool check(int p)
    {
        if(p%400==0)return 1;
        if(p%4==0&&p%100!=0)return 1;
        return 0;
    }
    int main()
    {
        int y;
        scanf("%d",&y);
        int ans = y+1;
        int p=(365+check(ans))%7;
        while(p!=0||check(y)!=check(ans))
            p=(p+365+check(++ans))%7;
        cout<<ans<<endl;
    }
  • 相关阅读:
    西门子SCL读写DB数据
    LeetCode8.字符串转换整数(atoi) JavaScript
    LeetCode8.字符串转换整数(atoi) JavaScript
    WebRequestSugar
    iosblock用法
    datasci
    UINavigationController学习笔记
    iOSTab bar
    自定义tab bar控件 学习资料
    Ios tab Bar 使用方法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5582686.html
Copyright © 2011-2022 走看看