测试点5,Re,求助

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

Summer77777 @ 2024-12-19 20:01:55

#include <stdio.h>

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

int main() {
    int x, y;
    scanf("%d %d", &x, &y);

    int leapYears[100];
    int leapCount = 0;

    for (int year = x; year <= y; ++year) {
        if (isLeapYear(year)) {
            leapYears[leapCount++] = year;
        }
    }

    printf("%d\n", leapCount);

    for (int i = 0; i < leapCount; ++i) {
        if (i > 0) printf(" ");
        printf("%d", leapYears[i]);
    }
    printf("\n");

    return 0;
}

by duantong @ 2024-12-19 20:07:32

#include <stdio.h>

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

int main() {
    int x, y;
    scanf("%d %d", &x, &y);

    int leapYears[3000];
    int leapCount = 0;

    for (int year = x; year <= y; ++year) {
        if (isLeapYear(year)) {
            leapYears[leapCount++] = year;
        }
    }

    printf("%d\n", leapCount);

    for (int i = 0; i < leapCount; ++i) {
        if (i > 0) printf(" ");
        printf("%d", leapYears[i]);
    }
    printf("\n");

    return 0;
}

by duantong @ 2024-12-19 20:07:47

@Summer77777 求关


by duantong @ 2024-12-19 20:08:18

第十四行


by Summer77777 @ 2024-12-19 20:48:49

@duantong 已关,谢谢


|