Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
39246 C++|刘一阳 展示闰年 C++ 通过 0 MS 252 KB 894 2024-01-31 14:34:28

Tests(1/1):


#include<iostream> using namespace std; bool isLeapYear(int year) { if (year%400==0) { return true; } else if (year%100==0) { return false; } else if (year%4==0) { return true; } else { return false; } } int countLeapYears(int x,int y) { int count=0; for (int year=x;year<=y;year++) { if (isLeapYear(year)) { count++; } } return count; } void printLeapYears(int x, int y) { bool isFirst=true; for (int i=x;i<=y;i++) { if (isLeapYear(i)) { if (!isFirst) { cout <<" "; } cout<<i; isFirst=false; } } } int main() { int x, y; cin>>x>>y; int leapYearCount=countLeapYears(x,y); cout <<leapYearCount<<" "; printLeapYears(x, y); return 0; }


测评信息: