跳到正文

个人记录

闰年展示

gg167868约 1 分钟
原文
文章信息与版本

文章信息

发布
2022年8月27日
收录
2026年1月10日
更新
2026年11月9日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>

using namespace std;

int l , r ;
bool check (int year)
{
    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) return 1 ;
    return 0 ;
}

int main()
{

    cin >> l >> r ;
    for (int first = l; first <= r; first++)
    {
        if (check (first))
        {
            int k = r - first ;
            int ans = k / 4 + 1 ;
            ans -= k / 100 ;
            ans += k / 400 ;
            cout << ans << endl ;
            for (int j = first; j <= r; j += 4)
            {
                if (j % 100 != 0) cout << j << ' ' ;
                else if (j % 400 == 0) cout << j << ' ' ;
            }
            return 0 ;
        }
    }
    cout << 0 ;

    return 0;
}
原文