ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1014. Product of Digits

why I got CE?Help please!
Posted by SunCat 12 Nov 2002 19:23
program Ural1014;
var result,work:array[1..40] of byte;
    n:longint;
    mstep:integer;

function search(t:integer;rest,last:longint):boolean;
var i:integer;
    temp:boolean;
begin
 if t=mstep+1 then
   begin
     if rest=1 then
      begin result:=work;search:=true end else search:=false;
     exit;
   end
 else
   begin
    for i:=last to 9 do
      if rest mod i =0 then
      begin
       work[t]:=i;
       temp:=search(t+1,rest div i,i);
       if temp then begin search:=true;exit end;
      end;
   end;
end;


procedure print;
var i:integer;
begin
 for i:=1 to mstep do write(result[i]);
 writeln;
end;

begin
 fillchar(result,sizeof(result),0);
 fillchar(work,sizeof(work),0);
 readln(n);
 if n=0 then begin writeln(10);exit end
 else
 for mstep:=1 to 30 do
  if search(1,n,2) then
     begin print;exit end;
 writeln(-1);
end.
Cange result to result1 and see in function seerch. maby i didn't change all reult to result1
Posted by I am david. Tabo. 12 Nov 2002 22:23
program Ural1014;
 var result1,work:array[1..40] of byte;
     n:longint;
     mstep:integer;

 function search(t:integer;rest,last:longint):boolean;
 var i,oo:integer;
     temp:boolean;
 begin
  if t=mstep+1 then
    begin
      if rest=1 then
       begin
         for oo:=1 to 40 do
           result1[oo]:=work[oo];
         search:=true
       end
      else
        search:=false;
      exit;
    end
  else
    begin
     for i:=last to 9 do
       if rest mod i =0 then
       begin
        work[t]:=i;
        temp:=search(t+1,rest div i,i);
        if temp then begin search:=true;exit end;
       end;
    end;
 end;


 procedure print;
 var i:integer;
 begin
  for i:=1 to mstep do write(result1[i]);
  writeln;
 end;

 begin
  fillchar(result1,sizeof(result1),0);
  fillchar(work,sizeof(work),0);
  readln(n);
  if n=0 then begin writeln(10);exit end
  else
  for mstep:=1 to 30 do
   if search(1,n,2) then
      begin print;exit end;
  writeln(-1);
 end.