洛谷-P5737 【深基7.例3】闰年展示

洛谷-P5737 【深基7.例3】闰年展示

原题链接:https://www.luogu.com.cn/problem/P5737


题目描述

输入 (x,y(1582le x < y le 3000)) ,输出 ([x,y]) 区间中闰年个数,并在下一行输出所有闰年年份数字,使用空格隔开。

输入格式

输出格式

输入输出样例

输入 #1

1989 2001

输出 #1

3
1992 1996 2000

C++代码

#include <iostream>
using namespace std;

int a[1500];

bool isLeapYear(int year) {
    return year % 100 != 0 && year % 4 == 0 || year % 400 == 0;
}

int main() {
    int x, y, k=0;
    cin >> x >> y;
    for (int i=x; i<=y; ++i)
        if (isLeapYear(i))
            a[k++] = i;
    cout << k << endl;
    for (int i=0; i<k; ++i)
        cout << a[i] << ' ';
    cout << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/yuzec/p/13394972.html