cxm1024 @ 2019-11-02 08:28:34
#include<iostream>
#include<cmath>
using namespace std;
int daynum[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
void jia(int *x)
{
(*x)++;
int nian=(*x)/10000,yue=(*x)/100%10000,ri=(*x)%100;
if(nian%400==0)daynum[2]=29;
else if(nian%100==0)daynum[2]=28;
else if(nian%4==0)daynum[2]=29;
else daynum[2]=28;
if(ri>daynum[yue])(*x)-=daynum[yue],(*x)+=100;
if(yue>12)(*x)-=1200,(*x)+=10000;
}
bool pd(int x)
{
bool b=1;
for(int i=1;i<=4;i++)
if(x%int(pow(10,i))/int(pow(10,i-1))!=x%int(pow(10,8-i+1))/int(pow(10,8-i)))
{
b=0;break;
}
return b;
}
int main()
{
int l,r,ans=0;
cin>>l>>r;
for(;l<=r;jia(&l))
if(pd(l))
ans++;
cout<<ans<<endl;
return 0;
}
by cxm1024 @ 2019-11-02 08:32:28
#include<iostream>
#include<cmath>
using namespace std;
int daynum[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool pd(int x)
{
bool b=1;
for(int i=1;i<=4;i++)
if(x%int(pow(10,i))/int(pow(10,i-1))!=x%int(pow(10,8-i+1))/int(pow(10,8-i)))
{
b=0;break;
}
return b;
}
int main()
{
int l,r,ans=0;
cin>>l>>r;
while(l<=r)
{
if(pd(l))ans++;
l++;
int nian=l/10000,yue=l/100%10000,ri=l%100;
if(nian%400==0)daynum[2]=29;
else if(nian%100==0)daynum[2]=28;
else if(nian%4==0)daynum[2]=29;
else daynum[2]=28;
if(ri>daynum[yue])l-=daynum[yue],l+=100;
if(yue>12)l-=1200,l+=10000;
}
cout<<ans<<endl;
return 0;
}
by Junthe @ 2019-11-02 08:40:01
by sandwich @ 2019-11-02 08:49:32
好像没什么毛病哦
by touxi @ 2020-06-11 19:26:55
daynum[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
by touxi @ 2020-06-11 19:27:14
daynum[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};