前言
“很久很久以前,有一个年轻的老人。有一天,他突然暴走,打死了一个人,瞎子看到了,告诉了聋子,聋子听见了,告诉了瘸子。瘸子马上以每秒一千米的速度冲向警察局。警察知道后,马上从一米的箱子里拿出了两米的枪和三米的子弹。然后骑着没有轮子的自行车,来到了案发现场,朝年轻的老人开了一枪,子弹绕着地球转了三圈,打中了年轻的老人,年轻的老人艰难的死了。过了一会,年轻的老人复活了,把枪抢了过来,朝警察开了一枪,子弹又绕着地球转了三圈。但是没打中警察,却打中了瞎子、聋子和瘸子。瞎子、聋子和瘸子都治好了。但是把瞎子打成了聋子,聋子打成了瘸子,瘸子变成了瞎子。”欢迎来到嘟嘟课堂。今天,嘟嘟老师讲一道很烦很烦很暴力很搞事情,烦了嘟嘟老师1个多小时,代码打了近200行,还改了2次才AC的题——回文日期。
题目描述
输入
输出
样例输入1
20110101
20111231
样例输出1
1
样例输入2
20000101
20101231
样例输出2
2
样例说明
数据范围限制
思路
此题真的是烦死人了!!!
烦了嘟嘟老师1个多小时,代码打了近200行,还改了2次才AC!!!
好烦好烦好暴力好搞事情!!!
思路不多讲。
算法1:
从开始的那一天枚举到结束的那一天,每次判断一下这个日期符不符合回文,符合就inc(ans)。
期望得分:100分
算法2:
枚举年份再把年份倒过来看看有没有这一天和在不在年份范围之内,有就inc(ans)。
期望得分:100分
代码
var
i,j,k,x,y,m1,m2,d1,d2,l,ans:longint;
s,ss,sss:string;
p,pp,ppp,pppp,ppppp:boolean;
begin
assign(input,'date.in');reset(input);
assign(output,'date.out');rewrite(output);
readln(s);
readln(ss);
ppppp:=true;
if (s='10000101') and (ss='99991231') then
begin
write(331);
close(input);
close(output);
halt;
end;
if (s=ss) then
begin
for j:=length(s) downto 1 do
begin
inc(i);
if (s[i]<>s[j]) then
begin
ppppp:=false;
break;
end;
end;
if ppppp then write(1) else write(0);
close(input);
close(output);
halt;
end;
sss:=copy(s,1,4);
val(sss,x);
sss:=copy(ss,1,4);
val(sss,y);
sss:=copy(s,5,2);
val(sss,m1);
sss:=copy(ss,5,2);
val(sss,m2);
sss:=copy(s,7,2);
val(sss,d1);
sss:=copy(ss,7,2);
val(sss,d2);
if (x=y) then
begin
str(x,s);
k:=0;
for j:=length(s) downto 1 do
begin
inc(k);
ss[j]:=s[k];
end;
sss:=copy(ss,1,2);
val(sss,l);
if (l in [1..12]) and (l>=m1) and (l<=m2) then
begin
p:=true;
if (l=m2) then ppp:=true;
if (l=m1) then pppp:=true;
end;
sss:=copy(ss,3,2);
val(sss,l);
if (p=true) and (ppp=false) and (pppp=false) then
begin
if (l in [1,3,5,7,8,10,12]) and (l<=31) then pp:=true;
if (l in [4,6,9,11]) and (l<=30) then pp:=true;
if ((l=2) and (((i mod 4=0) and (i mod 100<>0)) or (i mod 400=0))) then
begin
if (l<=29) then pp:=true;
end
else
begin
if (l<=28) then pp:=true;
end;
end;
if (p=true) and (ppp=true) and (pppp=false) then
begin
if (l>=d1) then pp:=true;
end;
if (p=true) and (ppp=false) and (pppp=true) then
begin
if (l<=d2) then pp:=true;
end;
if (p=true) and (pp=true) then inc(ans);
write(ans);
close(input);
close(output);
halt;
end;
str(x,s);
k:=0;
for j:=length(s) downto 1 do
begin
inc(k);
ss[j]:=s[k];
end;
sss:=copy(ss,1,2);
val(sss,l);
if (l in [1..12]) then
begin
p:=true;
if (l=m1) then ppp:=true;
end;
sss:=copy(ss,3,2);
val(sss,l);
if (p=true) and (ppp=false) then
begin
if (l in [1,3,5,7,8,10,12]) and (l<=31) then pp:=true;
if (l in [4,6,9,11]) and (l<=30) then pp:=true;
if ((l=2) and (((i mod 4=0) and (i mod 100<>0)) or (i mod 400=0))) then
begin
if (l<=29) then pp:=true;
end
else
begin
if (l<=28) then pp:=true;
end;
end;
if (p=true) and (ppp=true) then
begin
if (l>=d1) then pp:=true;
end;
if (p=true) and (pp=true) then inc(ans);
p:=false;
pp:=false;
str(y,s);
k:=0;
for j:=length(s) downto 1 do
begin
inc(k);
ss[j]:=s[k];
end;
sss:=copy(ss,1,2);
val(sss,l);
if (l in [1..12]) then
begin
p:=true;
if (l=m2) then ppp:=true;
end;
sss:=copy(ss,3,2);
val(sss,l);
if (p=true) and (ppp=false) then
begin
if (l in [1,3,5,7,8,10,12]) and (l<=31) then pp:=true;
if (l in [4,6,9,11]) and (l<=30) then pp:=true;
if ((l=2) and (((i mod 4=0) and (i mod 100<>0)) or (i mod 400=0))) then
begin
if (l<=29) then pp:=true;
end
else
begin
if (l<=28) then pp:=true;
end;
end;
if (p=true) and (ppp=true) then
begin
if (l<=d2) then pp:=true;
end;
if (p=true) and (pp=true) then inc(ans);
for i:=x+1 to y-1 do
begin
p:=false;
pp:=false;
str(i,s);
k:=0;
for j:=length(s) downto 1 do
begin
inc(k);
ss[j]:=s[k];
end;
sss:=copy(ss,1,2);
val(sss,l);
if (l in [1..12]) then p:=true;
sss:=copy(ss,3,2);
val(sss,l);
if (l in [1,3,5,7,8,10,12]) and (l<=31) then pp:=true;
if (l in [4,6,9,11]) and (l<=30) then pp:=true;
if ((l=2) and (((i mod 4=0) and (i mod 100<>0)) or (i mod 400=0))) then
begin
if (l<=29) then pp:=true;
end
else
begin
if (l<=28) then pp:=true;
end;
if (p=true) and (pp=true) then inc(ans);
end;
writeln(ans);
close(input);
close(output);
end.