输出多了一个0是怎么回事?求解答

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

RRTT @ 2020-06-09 20:46:43

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int hjysb,hjydsb;
int dhw(int a,int b)
{
    int i;
    int ans=0;
    int sg[10001];
    memset(sg,0,sizeof(sg));
    for(i=a;i<=b;i++)
    {
        if((i%4==0 && i%100!=0) || i%400==0)
        {
            sg[i]=i;
            ans++;
        }
    }
    printf("%d\n",ans);
    for(i=1582;i<=3000;i++)
    {
        if(sg[i]!=0)
        {
            printf("%d ",sg[i]);
        }           
    }
}
int main()
{
    scanf("%d %d",&hjysb,&hjydsb);
    printf("%d",dhw(hjysb,hjydsb));
    return 0;
}

by Chen_006 @ 2020-06-09 20:47:23

很好自己解


by B_lhx @ 2020-06-09 20:49:28

头像。。。


by Thomas_Cat @ 2020-06-09 20:55:06

头像。。。


by Ryo_Yamada @ 2020-06-09 20:55:26

头像。。。


by WanderingTrader @ 2020-06-09 21:03:38

头像。。。


by touxi @ 2020-08-15 19:18:33

int dhw(int a,int b)
void dhw(int a,int b)

by farmer_snack @ 2022-02-27 17:40:00

可过样例

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

#include<time.h>

#include<iostream>

#include<cstring>

#include<windows.h>
using namespace std;
int hjysb,hjydsb;
void gtxy(int x, int y);
void sqh(int a,int b);
int dhw(int a,int b)
{
    int i;
    int ans=0;
    int sg[10001];
    memset(sg,0,sizeof(sg));
    for(i=a;i<=b;i++)
    {
        if((i%4==0 && i%100!=0) || i%400==0)
        {
            sg[i]=i;
            ans++;
        }
    }
    printf("%d\n",ans);
    for(i=1582;i<=3000;i++)
    {
        if(sg[i]!=0)
        {
            printf("%d ",sg[i]);
        }
    }
}
int main()
{
    scanf("%d %d",&hjysb,&hjydsb);
    printf("%d",dhw(hjysb,hjydsb));
    gtxy(14,2);
    cout<<" ";
    return 0;
}
void gtxy(int x, int y)

{
  COORD zb;

  zb.X = x;

  zb.Y = y;

  SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), zb);

}
void  sgh(int a,int b)
{
    CONSOLE_CURSOR_INFO gb={1,0};

    SetConsoleCursorInfo( GetStdHandle(STD_OUTPUT_HANDLE), &gb );

}

编译环境:code::blocs


by farmer_snack @ 2022-03-06 08:26:38

@RRTT


by RRTT @ 2022-03-06 15:37:35

@kkksc03e 谢谢!


|