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

I have got WA on test 4, but I have prety good algorithm
Posted by Levani Kasradze 5 Sep 2004 21:35
var a: array[1..32] of Integer;
    n: Longint;
    i, j, sign, temp: Integer;
    flag: Boolean;

label fin;

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;
        Inc(sign);
        a[sign] := i;
        n := n div i;
        break;
      end;

  end;{While}

  if (n = 0) then
  begin
    writeln('-1');
    goto fin;
  end;

  if (n div 10 >= 1) then
  begin
    writeln('-1');
    goto fin;
  end;


  Inc(sign);
  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;

fin:

end.

Re: I have got WA on test 4, but I have prety good algorithm
Posted by Alatau [kaz] 8 Sep 2004 20:06
After readln(n);
You have to check n = 0 & n = 1:
- in first case you must output 10 (1 * 0 = 0),
- in second case you must output 1 (1 = 1).
In this cases after output you'll go to fin.

Good Luck.