HbugU @ 2021-05-21 20:33:52
#include<bits/stdc++.h>
using namespace std;
int ans;
bool hw(int num)
{
int tmp=num;
int sum=0;
for (int i=tmp;tmp;tmp /= 10) sum=sum*10+(tmp%10);
if (num==sum) return 1;
else return 0;
}
bool date(int number){
int x=number;
bool rn=0;
int y=floor(x/10000),m=floor(x%10000/100),d=x%1000000;
if((y%4==0&&y%100!=0)||y%400==0) rn=1;
if(m==1&&m==3&&m==5&&m==7&&m==8&&m==10&&12){
if(d!=31) {
return 0;
}
}if(m==2){
if(rn==1){
if(d!=29){
return 0;
}
}else{
if(d!=28){
return 0;
}
}
}else{
if(d!=30){
return 0;
}
}
return 1;
}
int a,b;
int main(){
cin>>a>>b;
for(int i=a;i<=b;i++){
if(hw(i)&&date(i)){
ans++;
}
}
cout<<ans;
return 0;
}
by luo_shen @ 2021-05-21 20:39:03
您确定是d!=31
?
by luo_shen @ 2021-05-21 21:02:49
@HbugU
因为dalao
您的代码里错误有点多,所以这边直接上代码,您看看
#include<bits/stdc++.h>
using namespace std;
int ans;
bool hw(int num)
{
int tmp=num;
int sum=0;
for (int i=tmp;tmp;tmp /= 10) sum=sum*10+(tmp%10);
if (num==sum) return 1;
else return 0;
}
bool date(int number){
int x=number;
bool rn=0;
int y=x/10000,m=x%10000/100,d=x%100;//错误一: x%1000000
if(m>12||m<1){
return 0;
}//错误二
if((y%4==0&&y%100!=0)||y%400==0) rn=1;
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12){//错误三:要用或
if(d>31) {
return 0;
}//错误四:不能用d!=31
}
else if(m==2){
if(rn==1){
if(d>29){
return 0;
}
}
else{
if(d>28){
return 0;
}
}
}
else{
if(d>30){
return 0;
}
}
return 1;
}
int a,b;
int main(){
cin>>a>>b;
for(int i=a;i<=b;i++){
if(hw(i)&&date(i)){
ans++;
}
}
cout<<ans;
return 0;
}
by HbugU @ 2021-05-21 21:16:32
谢谢
by HbugU @ 2021-05-21 21:20:24
@i_want_to_ak_ioi tle了,不过还是说声谢谢!