Home > Back-end >  How to use the most concise method, the output from a to ZZZZ
How to use the most concise method, the output from a to ZZZZ

Time:10-12

In the most concise way output from a b c... Z aa ab, ac... Zz... ZZZZ (length of four as a demo only), please give the code,

CodePudding user response:

The cycle is ok, need others to give the code?

CodePudding user response:

Nested loop

CodePudding user response:

1. According to the length of letters ordering
 var 
I, j, k: Byte;
The begin
For I:=97 to 122 the do
Mmo1. Lines. The Add (Char (I));
For I:=97 to 122 the do
For j:=97 to 122 the do
The begin
Mmo1. Lines. The Add (Char (I) + Char (j));
For k:=97 to 122 the do
end;
For I:=97 to 122 the do
For j:=97 to 122 the do
For k:=97 to 122 the do
The begin
Mmo1. Lines. The Add (Char (I) + Char (j) + Char (k));
end;
end;


2. According to the alphabetical order
 var 
I, j, k: Byte;
The begin
For I:=97 to 122 the do
The begin
Mmo1. Lines. The Add (Char (I));
For j:=97 to 122 the do
The begin
Mmo1. Lines. The Add (Char (I) + Char (j));
For k:=97 to 122 the do
Mmo1. Lines. The Add (Char (I) + Char (j) + Char (k));
end;
end;
end;

CodePudding user response:

 var 
I, j: Integer;
The begin
For I=1 to 4 do//here is you want to output the length of the string
The begin
For j:=word to word (' a ') (' z ') do
The begin
Memo1. Lines. The Add (StringOfChar (CRH (j), I));
end;
end;
end;

CodePudding user response:

reference 4 floor hongss response:
Delphi/Pascal code? 1234567891011 var I, j: Integer; The begin for I=1 to 4 do//here is you want to output the length of the string the begin for j:=word to word (' a ') (' z ') do the begin Memo1. Lines. The Add (StringOfChar (CRH (j), I)); .


Wrong, and that is a single character cycle,,

CodePudding user response:

 Type 
TOutLineProc=Procedure (Const Line: String);//output interface, and need to be initialized before invoking

//recursive each output
Procedure _OutPutAZ (Byte: Integer; CurrentByte: integer; Const Line: String; The CallBack: TOutLineProc);
Var
I: integer;
The begin
If CurrentByte=Byte then
For I:=word to word (' a ') (' z ') do the begin
{$IFDEF CPU64}
PChar (Int64 (Line) + CurrentByte) ^ :=Char (I);
{$ELSE}
PChar (Integer (Line) + CurrentByte) ^ :=Char (I);
{$ENDIF}
The CallBack (Line);
End
The else
For I:=word to word (' a ') (' z ') do the begin
{$IFDEF CPU64}
PChar (Int64 (Line) + CurrentByte) ^ :=Char (I);
{$ELSE}
PChar (Integer (Line) + CurrentByte) ^ :=Char (I);
{$ENDIF}
_OutPutAZ (Byte, CurrentByte + 1, Line, the CallBack);
end;
end;

//output, MaxByte for the largest number, the CallBack as the CallBack function, when there is a new will CallBack the process
Procedure OutPutA2Z (MaxByte: Integer; The CallBack: TOutLineProc);
Var
I: integer;
The Line: String;
The begin
For I:=1 to MaxByte do begin
SetLength (Line, I);
_OutPutAZ (I - 1, 0, the Line, the CallBack);
end;
end;


//the following method to invoke
//callback process execution is very frequent, so should consider memory Buffer to handle, whether write files or show
Procedure OutLineProc (Const Line: String);
The begin
//comment out this sentence is very fast and slow slow right here
Form1. Memo1. Lines. The Add (Line);
end;

Procedure TForm1. FormCreate (Sender: TObject);
The begin
OutPutA2Z (3, OutLineProc);//the time used to double-digit increase exponentially, please consider the biggest digits
end;

CodePudding user response:

 
The program az.
Type alpha26=string;//26 letters of the 26 hexadecimal number

The function pow_l (x: qword; N: longint) : qword;
Var I: longint;
Re: qword;
The begin
Re:=1;
I:=0;
While i<> N do the begin
Re:=re * x;
Inc (I);
end;
Pow_l:=re;

end;

The function num2A26 (x: qword; Len: longint) : alpha26;
Var I: longint;
Re: alpha26;
The begin
Setlength (re, len);
For I:=len downto do begin 1
Re: [I]=CRH (26 + x mod word (' a '));
X: x=div 26;
end;
Num2a26:=re;
end;

Procedure printA26 (len: longint);
Var I: qword;
The begin
I:=0;
While i<> Pow_l (26, len) do the begin
Write (num2A26 (I, len) : 8);
Inc (I);
end;
end;
Procedure printAllA26 (len: longint);
Var I: longint;
The begin
For I:=1 to len do
PrintA26 (I);
end;

Var n: qword;
The begin
Readln (n);
While (n> 0) do the begin
PrintAllA26 (n);
Readln (n);
end;
End.

The violence, no code optimization, pow_l can be optimized,

CodePudding user response:

 procedure TForm1. Button1Click (Sender: TObject); 
Var
I, j, k, o, m: Integer;
The begin
The for m:=1 to 4 do
The begin
For I:=65 to 90 the do
The begin
If m> 1 then
The begin
For j:=65 to 90 the do
The begin
If m & gt; 2 then
The begin
For k:=65 to 90 the do
The begin
If m & gt; 3 then
The begin
For: o=65 to 90 the do
The begin
Memo1. Lines. The Add (Char (I) + Char (j) + Char (k) + Char (o));
end;
end;
Memo1. Lines. The Add (Char (I) + Char (j) + Char (k));
end;
end;
Memo1. Lines. The Add (Char (I) + Char (j));
end;
end;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related