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 wrong? Please help me!
Posted by romiohoo 23 Apr 2003 17:58
program p1014;
var
  a:array[1..32]of integer;
  n:longint;
  i,j,sign,temp:integer;
  flag:boolean;
begin
  readln(n);
  sign:=0;
  flag:=true;
  while (n>=10)and flag do
    begin
      flag:=false;
      for i:=9 downto 2 do
        if n mod i=0 then
          begin
            flag:=true;
            sign:=sign+1;
            a[sign]:=i;
            n:=n div i;
            break
          end
    end;
  if not flag then
    begin
      writeln('?');
      halt
    end;
  sign:=sign+1;
  a[sign]:=n;
  for i:=1 to sign-1 do
    for j:=i+1 to sign do
      if a[i]>a[j] then
        begin
          temp:=a[i];
          a[i]:=a[j];
          a[j]:=temp
        end;
  for i:=1 to sign do
    write(a[i]);
  writeln
end.
Re: Why I got wrong? Please help me!
Posted by Ovchinnikov Georg 23 Apr 2003 18:37
> program p1014;
> var
>   a:array[1..32]of integer;
>   n:longint;
>   i,j,sign,temp:integer;
>   flag:boolean;
> begin
>   readln(n);
>   sign:=0;
>   flag:=true;
>   while (n>=10)and flag do
>     begin
>       flag:=false;
>       for i:=9 downto 2 do
>         if n mod i=0 then
>           begin
>             flag:=true;
>             sign:=sign+1;
>             a[sign]:=i;
>             n:=n div i;
>             break
>           end
>     end;
>   if not flag then
>     begin
>       writeln('?');
>       halt
>     end;
>   sign:=sign+1;
>   a[sign]:=n;
>   for i:=1 to sign-1 do
>     for j:=i+1 to sign do
>       if a[i]>a[j] then
>         begin
>           temp:=a[i];
>           a[i]:=a[j];
>           a[j]:=temp
>         end;
>   for i:=1 to sign do
>     write(a[i]);
>   writeln
> end.
Your program should print to the output the only number Q. If such a
number does not exist print –1.
But it not all is one more test at N=0. Think!
I've got AC!Thank you!
Posted by romiohoo 23 Apr 2003 19:02