为什么超时,只有90分?
查看原帖
为什么超时,只有90分?
6727
AndyGamma楼主2015/10/24 17:19
var zi,old,new:string;
    i,len:longint;
procedure zhengshu;
    var a:integer;
    begin
        for a:=1 to i do begin
            zi:=copy(old,a,1);
            insert(zi,new,1);
        end;
        while(new[1]='0')do begin
            delete(new,1,1);
            if new='0'then break;
        end;
        writeln(new);
    end;
procedure xiaoshu;
    var a,b:integer;
    begin
        b:=i;
        for a:=1 to i-1 do begin
            zi:=copy(old,a,1);
            insert(zi,new,1);
        end;
        zi:=copy(old,i,1);
        insert(zi,new,i);
        for a:=i+1 to len do begin
            zi:=copy(old,a,1);
            insert(zi,new,i+1);
        end;
        while (new[1]='0')do begin
            delete(new,1,1);
            dec(i);
            dec(len);
            if new[2]='.'then break;
        end;
        while (new[len]='0')and(new[len-1]<>old[b])do begin
            delete(new,len,1);
            dec(len);
        end;
        if new[len]='.'then insert('0',new,len+1);
        if new[1]='.'then begin
            insert('0',new,1);
            inc(i);
            inc(len);
        end;
        writeln(new);
    end;
procedure fenshu;
    var a,b:integer;
    begin
        b:=i;
        for a:=1 to i-1 do begin
            zi:=copy(old,a,1);
            insert(zi,new,1);
        end;
        zi:=copy(old,i,1);
        insert(zi,new,i);
        for a:=i+1 to len do begin
            zi:=copy(old,a,1);
            insert(zi,new,i+1);
        end;
        while new[1]='0'do begin
            delete(new,1,1);
            dec(i);
            dec(len);
        end;
        while new[i+1]='0'do begin
            delete(new,1+i,1);
            dec(len);
        end;
        if new[1]='/'then insert('0',new,1);
        writeln(new);
    end;
procedure baifenshu;
    var a:integer;
    begin
        delete(old,i,1);
        dec(i);
        for a:=1 to i do begin
            zi:=copy(old,a,1);
            insert(zi,new,1);
        end;
        while (new[1]='0')do begin
            delete(new,1,1);
            dec(i);
            if new[2]='%'then break;
        end;
        zi:='%';
        insert(zi,new,i+1);
        writeln(new);
    end;
begin
    readln(old);
    len:=length(old);
    for i:=1 to len do if old[i]='.'then begin
        xiaoshu;
        halt;
    end else if old[i]='%'then begin
        baifenshu;
        halt;
    end else if old[i]='/'then begin
        fenshu;
        halt;
    end;
    zhengshu;
end.

其中测试点5和20超时。 请高手们帮帮忙

2015/10/24 17:19
加载中...