原题解链接:https://ac.nowcoder.com/discuss/150007

做法一:

本题数据范围较小,可以直接暴力遍历所有日期。

做法二:

打表


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
struct date{
	int year;
	int morth;
	int day;
}; 
int daymap[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
date add(date &x){
	x.day++;
	if(x.day>daymap[x.morth]){
		x.morth++;
		x.day=1;
	}	
	if(x.morth>12){
		x.year++;
		x.morth=1;
	}
	return x;
}
bool cmp(date a,date b){
	if(a.year==b.year && a.morth==b.morth && a.day==b.day)
		return false;
	else return true;
}
bool solve(date x){
	char str[10];
	sprintf(str,"%04d%02d%02d",x.year,x.morth,x.day);
	if(str[0]==str[7] && str[1]==str[6] && str[2]==str[5] && str[3]==str[4])
		return true;
	else return false;
}
int main(){
	//freopen("date10.in","r",stdin);
	//freopen("date10.out","w",stdout);
	int T;
	date tmp;
	tmp.year=9220;
	tmp.morth=2;
	tmp.day=28;
	cin>>T;
	while(T--){
		date begin,end;
		int ans=0;
		scanf("%d-%d-%d",&begin.year,&begin.morth,&begin.day);
		scanf("%d-%d-%d",&end.year,&end.morth,&end.day);
		for(add(end);cmp(begin,end);add(begin)){
			if(solve(begin))ans++;
			if(!cmp(tmp,begin))ans++;
		}
		cout << ans << endl;
	}
	return 0;
}