Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

可以不用写递归啊,但代码较长。。不知道大家的思想和我的一不一样

Posted by 1017981912 at 2014-11-30 12:26:14 on Problem 2282
var
        s:string[9];
        shu:array[1..9] of longint;
        opera,operb:array[0..9] of longint;
        a,b,len,i,j,temp1,temp2,right,left:longint;

procedure work1;
var
        i,j,st:longint;
begin
        temp1:=1;
        temp2:=10;
        for i:=1 to len do
        begin
                right:=a mod temp1;
                left:=a div temp2;
                if i<>1 then
                begin
                        if left-1>0 then inc(opera[0],(left-1)*temp1);
                        for j:=1 to 9 do inc(opera[j],left*temp1);
                end
                else
                for j:=0 to 9 do inc(opera[j],left*temp1);
                st:=0;
                if (i=len) and (len<>1) then inc(st);
                for j:=st to shu[i]-1 do inc(opera[j],temp1);
                inc(opera[shu[i]],right+1);
                temp1:=temp1*10;
                temp2:=temp2*10;
        end;
end;

procedure work2;
var
        i,j,st:longint;
begin
        temp1:=1;
        temp2:=10;
        for i:=1 to len do
        begin
                right:=b mod temp1;
                left:=b div temp2;
                st:=0;
                if (i=len) and (len<>1) then inc(st);
                if i<>1 then
                begin
                        if left-1>0 then inc(operb[0],(left-1)*temp1);
                        for j:=1 to 9 do inc(operb[j],left*temp1);
                end
                else
               for j:=0 to 9 do inc(operb[j],left*temp1);
                for j:=st to shu[i]-1 do inc(operb[j],temp1);
                inc(operb[shu[i]],right+1);
                temp1:=temp1*10;
                temp2:=temp2*10;
        end;
end;

begin
        readln(a,b);
        while (a<>0) or (b<>0) do
        begin
                if a>b then
                begin
                        if b<>0 then dec(b);
                end
                else
                begin
                        if a<>0 then dec(a);
                end;
                fillchar(opera,sizeof(opera),0);
                str(a,s);
                len:=length(s);
                for i:=1 to len do shu[i]:=ord(s[len-i+1])-ord('0');
                work1;
                fillchar(operb,sizeof(operb),0);
                str(b,s);
                len:=length(s);
                for i:=1 to len do shu[i]:=ord(s[len-i+1])-ord('0');
                work2;
                for i:=0 to 8 do write(abs(opera[i]-operb[i]),' ');
                writeln(abs(opera[9]-operb[9]));
                readln(a,b);
        end;
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator