60昏求助

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

Coldstar_Qin @ 2024-10-15 19:46:23

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main() {
    int x, y, z = 0;
    scanf("%d %d",&x,&y);
    for (int i = x; i < y; i++) {
        if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
            z++;
        }
    }
    printf("%d\n", z);
    for (int i = x; i <= y; i++) {
        if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
            printf("%d ", i);
        }
    }
    return 0;
}

各位大佬看一下,输出是一样的,哪里有错,2和4wa了


by RainMeng666 @ 2024-10-17 21:32:14

@Coldstar_Qin 第六行改成<=y


by Coldstar_Qin @ 2024-10-20 19:35:03

@RainMeng666 好的好的,没问题了谢谢


by zhanghangyuqaq @ 2024-12-01 08:50:38

#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main(){
    int n,m;
    cin>>n>>m;
    int ans=0;
    for(int i=n;i<=m;i++){
        if(i%400==0||i%4==0&&i%100!=0){
            ans++;
            mp[ans]=i;
        }
    }
    cout<<ans<<endl;
    for(auto x:mp){
        cout<<x.second<<" ";
    }
    return 0;
}

|