revokemeplease @ 2017-07-28 14:12:18
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int i;
bool rn(int y)
{
if(y%4==0&&y%100!=0)
return 1;
else if(y%400==0)
return 1;
return 0;
}
int generator(int y)
{
int ans=y*10000+y/1000+y/100%10*10+y/10%100*100+y%10*1000;
return ans;
}
bool checker(int h)
{
int day=h%100;
int month=h/100%100;
if(month<=12&&month>0)
if(month==2&&rn(i))
{
if(day>0&&day<29)
return 1;
}
else if(month==2&&rn(i)!=1)
{
if(day>0&&day<28)
return 1;
}
else if(month==1&&month==3&&month==5&&month==7&&month==8&&month==10&&month==12)
{
if(day>0&&day<=31)
return 1;
}
else
{
if(day>0&&day<=30)
return 1;
}
return 0;
}
int main()
{
int sdate,edate,huiyear,tot=0,temp;
cin>>sdate>>edate;
int syear=sdate/10000,eyear=edate/10000;
for(i=syear;i<=eyear;i++)
{
temp=generator(i);
if(checker(temp))
tot++;
}
//cout<<syear<<" "<<eyear;
cout<<tot;
return 0;
}
by angleの奏 @ 2017-08-12 13:49:07
你咋写那么长
by Erusel @ 2017-08-16 09:25:40
bool ky(int a)
{
int t=a/100-a/10000*100,s=a%100;
if((t==2&&s<=28) || (rn(a)==true&&s<=29))return true;
if(t==1||t==3||t==5||t==7||t==8||t==10||t==12)if(s<=31)return true;//大月
if(t==4||t==6||t==9||t==11)if(s<=30)return true;
return false;
}
by Erusel @ 2017-08-16 09:28:07
整理一下第三个函数的代码
by zanghongyi @ 2017-09-25 21:53:25
#include<iostream>
using namespace std;
int i,j,n,m,a,b,c,sum,ans;
int s[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main()
{
cin>>n>>m;
for (i=1;i<=12;i++)
for (j=1;j<=s[i];j++)
{
c=(j%10)*1000+
(j/10)*100+
(i%10)*10+
(i/10);
sum=c*10000+i*100+j;
if (sum<n||sum>m) continue;
ans++;
}
cout<<ans;
return 0;
}
by zanghongyi @ 2017-09-25 21:53:59
发个题解