Zhe8468 @ 2020-08-02 23:42:50
#include <bits/stdc++.h>
bool runnian(int date){
int year = date/10000;
if((year%4==0&&year%100!=0)||(year%400==0)){
return true;
}else return false;
}
bool huiwenshu(int date){
int temp = date,ans=0;
while(temp>0){
ans = ans*10+temp%10;
temp/=10;
}
if(ans==date) return true;
else return false;
}
bool riqi(int date){
int year = date/10000;
int month = (date/100)%100;
int day = date%100;
bool b_month = false;
bool b_day = false;
if(month>=1&&month<=12) b_month = true;
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:{
if(day==31) b_day = true;
break;
}
case 4:
case 6:
case 9:
case 11:{
if(day==30) b_day = true;
break;
}
case 2:{
if(runnian(year)){
if(day==29) b_day = true;
}else{
if(day==28) b_day = true;
}
break;
}
}
if(b_month&&b_day) return true;
else return false;
}
using namespace std;
int main()
{
int date1,date2,sum=0;
cin>>date1>>date2;
for(int i=date1;i<=date2;i++){
if(riqi(i)&&huiwenshu(i)) sum++;
}
cout<<sum<<endl;
return 0;
}
by metaphysis @ 2020-08-03 07:47:51
@Zhe8468
日期判断有问题,当判断天数是否合法时,应该检查天数是否小于等于当月的最大天数而不应使用等于号来检查。
by Zhe8468 @ 2020-08-03 09:18:18
@metaphysis 是的 现在解决了 其实还需要一个TLE的优化 不然只能90分