80哇~,大神快帮我!

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

makeway @ 2024-11-30 13:33:06

样例已过

#include<bits/stdc++.h>
using namespace std;
int x,y,z;
int main()
{
    cin>>x>>y;
    for(int i=x;i<y;i++)
    {
        if(i%4==0&&i%100!=0)z++;
        else if(i%400==0)z++;
    }
    cout<<z<<"\n";
    for(int i=x;i<y;i++)
    {
        if(i%4==0&&i%100!=0)cout<<i<<" ";
        else if(i%400==0)cout<<i<<" ";
    }
    return 0;
}

by WuJiaNuo19 @ 2024-11-30 13:39:18

把for中的<y改成<=y


by WuJiaNuo19 @ 2024-11-30 13:39:32

@makeway


by makeway @ 2024-11-30 13:40:59

@WuJiaNuo19 为啥子?????


by tujize @ 2024-11-30 13:42:26

#include<bits/stdc++.h>
using namespace std;
int x,y,z;
int main()
{
    cin>>x>>y;
    for(int i=x;i<=y;i++)
    {
        if(i%4==0&&i%100!=0)z++;
        else if(i%400==0)z++;
    }
    cout<<z<<"\n";
    for(int i=x;i<=y;i++)
    {
        if(i%4==0&&i%100!=0)cout<<i<<" ";
        else if(i%400==0)cout<<i<<" ";
    }
    return 0;
}

by xiaojuzia @ 2024-11-30 13:57:32

@makeway 题目是求[x,y]区间中的闰年


by xiaojuzia @ 2024-11-30 13:58:50

@makeway 就相当于是x,y都要看是不是闰年


by makeway @ 2024-11-30 16:27:46

@xiaojuzia OK


|