麻烦大佬们帮忙看一下哪儿有问题,谢谢谢谢谢

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

yuyuyuyu12345 @ 2022-08-23 16:36:43

#include <iostream>
using namespace std;
int a[100],k;
int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    for(int i=x;i<=y;i++)
    {
        if((i%4==0&&i%100!=0)||i%400==0){
            a[k++]=i;
        }
    }
    cout<<k<<endl;
    for(int i=0;i<k;i++) cout<<a[i]<<" ";
}

by caramel_qwq @ 2022-08-23 16:39:41

@yuyuyuyu12345 你的数组开小了,可以开大一点


by caramel_qwq @ 2022-08-23 16:40:55

@yuyuyuyu12345 开个258试试(应该是243个闰年)


by tommyfj @ 2022-08-23 17:00:21

@yuyuyuyu12345 开到3000


by tommyfj @ 2022-08-23 17:03:16

@caramel_qwq 当x = 1,y = 3000,开到258就不够了


by caramel_qwq @ 2022-08-23 17:18:45

@tommyfj 1582\le x < y \le 3000 dalao看一下题?


by caramel_qwq @ 2022-08-23 17:19:00

@tommyfj x最多到1582啊


by yuyuyuyu12345 @ 2022-08-23 17:29:53

@caramel_qwq 哇,谢谢谢谢大佬,解决啦


by yuyuyuyu12345 @ 2022-08-23 17:30:35

@tommyfj 谢谢谢谢谢大佬,解决啦


by tommyfj @ 2022-08-23 17:55:29

@caramel_qwq 哦,应该是最少,但开到258还是不够啊


by BL_liuyuxuan @ 2022-10-06 12:04:20

数组应该(yiding)太小了

int a[100],k;


| 下一页