回文日期

前言
“很久很久以前,有一个年轻的老人。有一天,他突然暴走,打死了一个人,瞎子看到了,告诉了聋子,聋子听见了,告诉了瘸子。瘸子马上以每秒一千米的速度冲向警察局。警察知道后,马上从一米的箱子里拿出了两米的枪和三米的子弹。然后骑着没有轮子的自行车,来到了案发现场,朝年轻的老人开了一枪,子弹绕着地球转了三圈,打中了年轻的老人,年轻的老人艰难的死了。过了一会,年轻的老人复活了,把枪抢了过来,朝警察开了一枪,子弹又绕着地球转了三圈。但是没打中警察,却打中了瞎子、聋子和瘸子。瞎子、聋子和瘸子都治好了。但是把瞎子打成了聋子,聋子打成了瘸子,瘸子变成了瞎子。”欢迎来到嘟嘟课堂。今天,嘟嘟老师讲一道很烦很烦很暴力很搞事情,烦了嘟嘟老师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.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值