Home > Software engineering >  The dynamic array of each element, the combination of two, three three combination... , the problem
The dynamic array of each element, the combination of two, three three combination... , the problem

Time:10-07

Everyone a great god, ask a question,
Dynamic array of each element (element number N, up to 10), two combinations, three three combination, combination of NN,,,,,,,,, then, is that all combinations of all arranged,
Arrays, for example, a (10) are in the east, west, south, north, in the hair, white,,,,,,,,
Two combined into two: things, east, southeast, south east,,,,,,,,
Three three combinations: south, southeast, southwest, east, west, southeast of south and south east
Found white, grey, white, white hair, white hair, Bai Zhongfa
,,,,,,,,
The unevenness combination:,,,,,,,,
Combination of NN,,,,,,,,,

Then generate a combination of storage in a TXT documents,

CodePudding user response:

For reference only, although is a C language:
//QPLW CPP 
#include
#include
#include
Int v=0;
Int w=0;
int m;//record the length of the string
int n;//record the number of types of characters in a string
Char map [256].//record is what kind of character
Int count [256];//record each character how many
Int stack [1000];//recursive stack, and record the arrangement of the current generation
Void Make_Map (char * STR) {//statistics the related information of the string
Int s [256];
int i;
Memset (s, 0, sizeof (s));
Memset (count, 0, sizeof (count));
M=strlen (STR);
If (w<1 | | mWhile (* STR) {
S [* STR] + +;
Str++;
}
N=0;
for (i=0; i<256; I++)
If (s) [I] {
The map [n]=I;
The count [n] [I]=s;
n++;
}
}
Void the Find (int the depth) {//recursion backtracking generating permutations
If (the depth==w) {
int i;
for (i=0; iPutchar (" \ n ");
} else {
int i;
If (v & amp; & Depth> 0 {
for (i=0; iPutchar (" \ n ");
}
for (i=0; iIf (count [I]) {
Stack [the depth]=I;
The count [I] -;
Find the depth (+ 1);
The count [I] + +;
}
}
}
Void main (int arg c, char * * argv) {
If (argc<2) {
Printf (" % s to produce the whole arrangement of string [limited length | - 1] \ n ", argv [0]).
return;
}
If (argc>=3) w=atoi (argv [2]).
If (1==w) v=1;
Make_Map (argv [1]);
Find (0);
}
//C: \ test> QPLW
//QPLW to produce the whole arrangement of string] [finite length | - 1
//
//C: \ test> QPLW 123
//123
//132
//213
//231
//312
//321
//
//C: \ test> QPLW 123 2
//12
//13
//21
//23
//31
//32
//
//C: \ test> QPLW 122333
//122
//123
//132
//133
//212
//213
//221
//223
//231
//232
//233
//312
//313
//321
//322
//323
//331
//332
//333
//
//C: \ test> QPLW 123-1
//1
//12
//123
//13
//132
//2
//21
//213
//23
//231
//3
//31
//312
//32
//321
//

CodePudding user response:

Looks like a mahjong game

CodePudding user response:

Recursion can
 Dim t 
Private Sub Command1_Click ()
Dim arr () As String, I As Long
T=Split (" in the east, west, south, north, and hair and white ", ", ")
Open "d: \ MJ. TXT" For the Output As the # 1
For I=2 To UBound (t) + 1
Getall UBound (t), I, "", arr
Print # 1, the Join (arr. ", ") & amp; VbCrLf

Next
Close # 1
MsgBox "OK"
End Sub


Sub getall (ByVal m As Byte, ByVal n As Byte, ByRef As a String, ByRef arr () As String, Optional ByRef count As Long)
If Len (a)=n Then
The count=count + 1
ReDim Preserve arr To count (1)
Arr (count)=a
The Exit Sub
End the If
For I=0 To m
If InStr (a, t (I))=0 Then getall m, n, a. & amp; T (I), arr, count
Next I
End Sub
  • Related