|
|
вернуться в форумI have got WA on test 4, but I have prety good algorithm 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 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. |
|
|