记录编号 469945 评测结果 AAAAAAAAAA
题目名称 [NOIP 2016PJ]回文日期 最终得分 100
用户昵称 Gravatar爆零自动机 是否通过 通过
代码语言 C++ 运行时间 0.002 s
提交时间 2017-11-03 22:27:11 内存使用 0.31 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <climits>
#include <cstdlib>
using namespace std;

int date1,date2;
int year1,year2,m1,m2,d1,d2;
int dm,dd;
int cnt;
bool fyear(int year1);
int fday(int year1);
int fmonth(int year1);
bool run(int year1);
int main()
{
	freopen("datea.in","r",stdin);
	freopen("datea.out","w",stdout); //331
	
	cin>>date1>>date2;
	year1=date1/10000;
	year2=date2/10000;
	m1=(date1%10000)/1e2;
	m2=(date2%10000)/1e2;
	d1=date1%100;
	d2=date2%100;
	
	if(fyear(year1))
	{
		dm=fmonth(year1);
		dd=fday(year1);
		if(dm>m1)
			cnt++;
		else if(dm==m1 && dd>=d1)
			cnt++;
	}
	for(int i=year1+1; i<year2; i++)
	{
		if(fyear(i)) cnt++;
	}
	
	if(year1!=year2 && fyear(year2))
	{
		dm=fmonth(year2);
		dd=fday(year2);
		if(dm<m2)
			cnt++;
		
		else if(dm==m2 && dd<=d2)
			cnt++;
	}
	cout<<cnt<<endl;

	return 0;
}
int fmonth(int year1)
{
	return (year1%10*10+(year1%100)/10);
}
int fday(int year1)
{
	return ((year1/100)%10*10)+(year1/1000);
}
bool run(int year1)
{
	if(year1%4==0 && year1%100!=0) return true;
	if(year1%400==0) return true;
	return false;
}
bool fyear(int year1)
{
	int day=fday(year1);
	int month=fmonth(year1);
	if(month>12 || month==0 || day==0) return false;
	switch (month)
	{
		case 1:
			if(day>31) return false; break;
		case 2:
			if(day>29 || (!run(year1) && day>28)) return false; break;
		case 3:
			if(day>31) return false; break;
		case 4:
			if(day>30) return false; break;
		case 5:
			if(day>31) return false; break;
		case 6:
			if(day>30) return false; break;
		case 7:
			if(day>31) return false; break;
		case 8:
			if(day>31) return false; break;
		case 9:
			if(day>30) return false; break;
		case 10:
			if(day>31) return false; break;
		case 11:
			if(day>30) return false; break;
		case 12:
			if(day>31) return false; break;
	}
	return true;
}