文章
55
粉丝
100
获赞
12
访问
31.1k
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
struct Date{
int year;
int month;
int day;
};
int main(){
struct Date date;
int day[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int sum=0;
while(cin>>date.year>>date.month>>date.day){//判断日期输入是否合法
if(date.month>=1&&date.month<=12 && date.day>=0&&date.day<=day[date.month]){
bool Leap = date.year % 400 == 0 || (date.year % 100 != 0&&date.year%4==0);//判断是否为闰年
if(Leap){
day[2] = 29;
}else{
day[2] = 28;
}
for(int i = 1; i < date.month; i++){
sum+=day[i];//把该月之前的天数都加上
}
sum += date.day; //加上本月天数
cout<<sum<<endl;
sum = 0;
}else{
cout<<"Input error!"<<endl;
}
...
登录后发布评论
暂无评论,来抢沙发