bcbgszyzh @ 2023-09-03 16:30:07
请老师或大佬们帮助,谢谢。
code:
//C++
#include<bits/stdc++.h>
using namespace std;
int DayNum[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};
bool p(int x){
if( x%4==0 && x%100!=0|| x%400==0 )
return true;
else
return false;
}
int main(){
int a,b;
cin>>a>>b;
int cnt=0;
for(int i=a/10000;i<=b/10000;++i) {
if(p(i))DayNum[2]++;
int x=(i%10)*10+i/10%10,y=(i/100%10)*10+i/1000;
if(x>=1&&x<=12){
if(y>=1&&y<=DayNum[x]){
cnt++;
continue;
}
}
if(p(i))DayNum[2]--;
}
printf("%d",cnt);
return 0;
}
by bcbgszyzh @ 2023-09-03 16:30:58
样例全部
by rainbow_cat @ 2023-09-03 16:45:15
#include<bits/stdc++.h>
using namespace std;
int da[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int reint(int x)
{
int t;
string s=to_string(x);
string b(s.rbegin(),s.rend());
t=stoi(b);
return t;
}
int main()
{
int a,b,sty,stm,std,edy,edm,edd,aa,ans=0;
cin>>a>>b;
sty=a/10000;
edy=b/10000;
for(int i=sty;i<=edy;i++)
{
if(i%100!=0&&i%4==0||i%400==0)
{
da[2]=29;
}
else
{
da[2]=28;
}
int r=reint(i),z,x;
int data=i*10000+r;
z=r%100;
r/=100;
x=r;
if(x>=1&&x<=12&&z>=1&&z<=da[x]&&data>=a&&data<=b)
{
ans++;
}
}
cout<<ans;
return 0;
}
参考一下我的
by rainbow_cat @ 2023-09-03 16:45:30
@bcbgszyzh