讨论 / 不简洁的做法(懒得优化)
Snake52996 2017-10-23 20:13:47
点我顶贴 收藏 删除
#include<iostream>

using namespace std;

const int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool isr(int a)

{

if(a%400==0) return 1;

if(a%100!=0 && a%4==0) return 1;

return 0;

}

int main()

{

int a,b;

cin>>a>>b;

int ay,am,ad,by,bm,bd;

ay=a/10000;

by=b/10000;

am=(a/100)%100;

bm=(b/100)%100;

ad=a%100;

bd=b%100;

int co=0;

for(int i=ay;i<=by;i++)

{

int mon,day;

mon=i%100;

day=i/100;

//cout<<temp1<<" "<<temp2<<endl;

mon=(mon/10)+(mon%10)*10;

day=(day/10)+(day%10)*10;

//cout<<temp1<<" "<<temp2<<endl;

bool t=1;

if((i==ay && (mon<am || (mon==am && day<ad))) || (i==by && (mon>bm || (mon==bm && day>bd)))) continue;

if((mon==2 && isr(i) && day<=29) || (mon==2 && !isr(i) && day<=28)) {co++;continue;}

else if(mon==2) continue;

if(mon>12) continue;

else if(day>days[mon]) continue;

co++;

}

cout<<co;

return 0;

}

查看更多回复
提交回复