2456: 【入门】【P5737】闰年展示

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:43 解决:18

题目描述

输入 lns="http://www.w3.org/1998/Math/MathML">,,输出 lns="http://www.w3.org/1998/Math/MathML">[,] 区间中闰年个数,并在下一行输出所有闰年年份数字,使用空格隔开。

输入

输入两个正整数 lns="http://www.w3.org/1998/Math/MathML">,,以空格隔开。

输出

第一行输出一个正整数,表示 lns="http://www.w3.org/1998/Math/MathML">[,] 区间中闰年个数。

第二行输出若干个正整数,按照年份单调递增的顺序输出所有闰年年份数字。

样例输入 复制

1989 2001

样例输出 复制

3
1992 1996 2000

提示

数据保证,lns="http://www.w3.org/1998/Math/MathML">1582<3000


#include<iostream>
using namespace std;
int x,y,ans[500],cnt;
int main(){
    cin>>x>>y;
    for(int i=x;i<=y;i++)
        if(!(i%400) || !(i%4) && i%100) //之前章节介绍过的闰年判断,也可写成if(i%400==0 || i%4==0 && i%100!=0)
            ans[cnt++]=i; //等同于ans[cnt]=i,cnt++;
    cout<<cnt<<endl;
    for(int i=0;i<cnt;i++)
        cout<<ans[i]<<" ";
	cout<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
void init(); //定义读入部分
void doit(); //定义处理部分
void output(); //定义输出部分
int x,y,ans[500],cnt;
int main(){
	init();  //读入部分 
	doit();  //处理部分 
	output();  //输出部分 
	return 0;
}
void init() {
	cin>>x>>y;
}
void doit() {
	for(int i=x;i<=y;i++)
	    if(!(i%400) || !(i%4)&&i%100)
	        ans[cnt++]=i;
}
void output() {
	cout<<cnt<<endl;
	for(int i=0;i<cnt;i++)
	    cout<<ans[i]<<" ";
	cout<<endl;
}