自己发现了个Bug,但不是修正123456这组数据的.
请问,123456一共有多少组解?
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
const
MaxLength = 1000;
type
TNode = record
Used: array [1..MaxLength] of Boolean;
Sum: Byte;
d: Integer
end;
var
Num: array [1..MaxLength] of Byte;
Len: Integer;
Stack: array [1..MaxLength] of TNode;
Top: Integer;
procedure Init;
var
s: string;
i: Integer;
begin
Write('Input s: ');
ReadLn(s);
Len:=Length(s);
if Len>MaxLength then
begin
WriteLn('Too length!');
Halt
end;
for i:=1 to Lendo
begin
Num:=Ord(s)-Ord('0');
if Num>9 then
begin
WriteLn('Input error!');
Halt
end
end;
Top:=1;
FillChar(Stack[Top].Used, SizeOf(Stack[Top].Used), 0);
Stack[Top].Sum:=0;
Stack[Top].d:=0
end;
procedure Print(Node: TNode);
var
i: Integer;
begin
for i:=1 to Lendo
if Node.Used then
Write(Num, ' ');
WriteLn
end;
begin
Init;
while Top>0do
begin
while Stack[Top].d<Lendo
begin
Inc(Stack[Top].d);
if not Stack[Top].Used[Stack[Top].d] then
begin
Inc(Top);
Stack[Top]:=Stack[Top-1];
Stack[Top].Used[Stack[Top].d]:=True;
Stack[Top].Sum:=Stack[Top].Sum+Num[Stack[Top].d];
if Stack[Top].Sum=10 then
Print(Stack[Top])
end
end;
Dec(Top)
end;
ReadLn
end.