离谱的02优化
查看原帖
离谱的02优化
673730
yinqf楼主2022/10/11 08:41

82分代码:

#include<bits/stdc++.h>
using namespace std;
int a,b,ans;
int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int huiwen(int x){
	int xh=0,xz=0,t=0;
	xz=x;
	while(t<=7){
		xh=xh*10+x%10;
		x=x/10;
		t++;
	}
	if(xh==xz){
		return 1;
	}
	return 0;
}
int possible(int x){
	int year,mouth,day;
	year=x/10000;
	mouth=x%10000/100;
	day=x%100;
	if((year%4==0&&year%100!=0||year%400==0)&&mouth==2){//这个年份是4的整数倍,不是100的整数倍,是400的整数倍;
		if(day<=29){
			return 1;
		}
		else{
			return 0;
		}
	}
	else{
		if(mouth<=12){
			if(day<=m[mouth]){
				return 1;
			}
			else{
				return 0;
			}
		}
		else{
			return 0;
		}
	}
	
}
int main(){
	cin >> a >> b;
	for(int i=a;i<=b;i++){
		if(huiwen(i)&&possible(i)){
			ans++;
		}
	}
	cout << ans;
	return 0;
}

开02就AC了!!!

离谱!!!

2022/10/11 08:41
加载中...