题解 P2010 【回文日期】
程序员文章站
2022-05-14 18:17:43
...
蒟蒻来这只是给各位大佬看看我鬼畜的码风的
#include<cstdio>
#include<string>
#include<iostream>
#include<cstdlib>
using namespace std;
string s1,s2;
int ans;
bool check(string s)
{
int len=s.length()-1;
for(int i=0;i<len/2;i++)
{
if(s[i]!=s[len-i]) return false;
}
return true;
}
int day1[13]={-1,31,28,31,30,31,30,31,31,30,31,30,31};
int day2[13]={-1,31,29,31,30,31,30,31,31,30,31,30,31};
int main()
{
cin >> s1 >> s2;
if(s1==s2)
{
if(check(s1)) printf("1\n");
else printf("0\n");
exit(0);
}
int year1=0;
for(int i=0;i<4;i++)
{
year1=year1*10+s1[i]-48;
}
int year2=0;
for(int i=0;i<4;i++)
{
year2=year2*10+s2[i]-48;
}
int tt1=0,tt2=0;
for(int i=4;i<=7;i++)
{
tt1=tt1*10+s1[i]-48;
tt2=tt2*10+s2[i]-48;
}
int t1,t2,tmp;
t1=year1%100;
t2=year1/100;
t1=t1%10*10+t1/10;
t2=t2%10*10+t2/10;
tmp=t1*100+t2;
//cout << t1 <<" " << t2 << " " << tt1 << endl;
if(t1>=1 && t1<=12 && tmp>=tt1)
{
if((year1%4==0 && year1%100!=0) || (year1%400==0))
{
if(t2>day2[t1]);
else ans++;
}
else{
if(t2>day1[t1]);
else ans++;
}
}
t1=year2%100;
t2=year2/100;
t1=t1%10*10+t1/10;
t2=t2%10*10+t2/10;
tmp=t1*100+t2;
// cout << t1 <<" " << t2 << " " << tt2 << endl;
if(t1>=1 && t1<=12 && tmp<=tt2 && year1!=year2)
{
if((year2%4==0 && year2%100!=0) || (year2%400==0))
{
if(t2>day2[t1] ) ;
else ans++;
}
else{
if(t2>day1[t1]) ;
else ans++;
}
}
for(int year=year1+1;year<=year2-1;year++)
{
int mon=year%100;
int day=year/100;
mon=mon%10*10+mon/10;
day=day%10*10+day/10;
if(mon<1 || mon >12) continue;
if(day <1 || day>31) continue;
if((year%4==0 && year%100!=0) || year%400==0)
{
if(day2[mon]<day) continue;
ans++;
}
else{
if(day1[mon]<day) continue;
ans++;
}
}
printf("%d\n",ans);
return 0;
}
上一篇: P1226 【模板】快速幂||取余运算
下一篇: P1141 01迷宫