文章
3
粉丝
217
获赞
2
访问
8.7k
基本思路:算year1到year2的总共天数,然后减去多算的天数,多算的天数可以通过参考“已知日期求该日是这年的第几天”求出。
#include<bits/stdc++.h>
using namespace std;
int main(){
int year1,month1,day1;
int year2,month2,day2;
int f[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
scanf("%4d%2d%2d",&year1,&month1,&day1);
scanf("%4d%2d%2d",&year2,&month2,&day2);
int sum=0,sum1=day1,sum2=day2;
for(int i=year1;i<=year2;i++){
if(i%400==0||(i%4==0&&i%100!=0)) sum+=366;
else sum+=365;
}
if(year1%400==0||year1%4==0&&year1%100!=0) f[2]=29;
else f[2]=28;
for(int i=1;i<month1;i++){
sum1+=f[i];
}
//cout<<sum1;
if(year2%400==0||year2%4==0&&year2...
登录后发布评论
暂无评论,来抢沙发