Home > Back-end >  Three sheep in delight, with recursive output is not the end, for bosses to help have a look
Three sheep in delight, with recursive output is not the end, for bosses to help have a look

Time:03-05

# include
Void test (int a [])
{int x, y, z;
X=a [0] + a * 10 + [1] [2] a * 100 + a, [3] * 1000. Y=a + [1] a [4] * 10 + a 100 + a [6] [5] * * 1000; Z=a [7] + a * 10 + [1] [2] a * 100 * 1000 + a + a [5] [6] * 10000; If (x + y==z& & A [3]!=0 & amp; & A [6]!=0)
{printf (" % d % d % d % d ", a [6], a [5], a [4], a [1]). }
}
Void DFS (int a [], int k)
{int I, t;
If (k>=10)
{test (a); return; }
For (I=k; i<10; I++)
{
T=a [I]; A [I]=a, [k]. A [k]=t; DFS (a, k + 1); T=a [I]; A [I]=a, [k]. A [k]=t;
}
}
Int main ()
{int a []=,1,2,3,4,5,6,7,8,9 {0}. DFS (a, 0); return 0; }

CodePudding user response:

"Given a bit of input, a complete single-step tracking (and press Alt + 7 key to view the Call Stack from the inside to the following out of from the inner to outer function Call history) again," is your least-hassle route to understand the working principle of the recursive function!
Recursive function pay attention to the following factors
Exit criteria,
What parameters,
What, the return value is
What are local variables,
What are global variables,
When output,
, will not lead to stack overflow

CodePudding user response:

 # include & lt; Stdio. H> 
Int count;
Int OKcount;
Void test (int a [])
{
Int x, y, z;
int i;
If (count %==0 36288) {
for (i=0; i<10; I++) printf (" % d ", a [I]);
printf("\n");
}
count++;
X=a [0] + a * 10 + [1] [2] a * 100 + a, [3] * 1000.
Y=a + [1] a [4] * 10 + a 100 + a [6] [5] * * 1000;
Z=a [7] + a * 10 + [1] [2] a * 100 * 1000 + a + a [5] [6] * 10000;
If (x + y==z & amp; & A [3]!=0 & amp; & A [6]!=0) {
Printf (" OK "% d: % d % d % d % d \ n", OKcount, a [6], a [5], a [4], a [1]).
OKcount++;
}
}
Void DFS (int a [], int k)
{
Int I, t;
If (k>=10) {
The test (a);
return;
}
For (I=k; i<10; I++) {
T=a [I]; A [I]=a, [k]. A [k]=t;
DFS (a, k + 1);
T=a [I]; A [I]=a, [k]. A [k]=t;
}
}
Int main ()
{
Int a []=,1,2,3,4,5,6,7,8,9 {0};
Count=0;
OKcount=0;
DFS (a, 0);
Printf (" total count: % d \ n ", count);
Printf (" OKcount: % d \ n ", OKcount);
return 0;
}
//0 1 2 3 4 5 6 7 8 9
//0 1 9 3 4 6 7 8 2 5
//0 2 8 1 9 5 6 7 4 3
//0 3 2 5 6 7 4 1 8 and 9
//0 June 8 July 1 2 3 4 5 9
//0 5 6 7 1 2 3 4 8 9
//0 4 5 6 7 3 2 1 8 and 9
//0, 7, 4, 5, 8 and 9 June 1 2 3
//0 1 2 3 4 5 6 7 8 9
//0 9 2 1, 3, 4, 5 6 7 8
//0 1 2 3 4 5 6 7 8 9
//1 0 9 4 6 7 8 2 5 3
//1 2 8 5 0 9 6 7 4 3
//1 3 2 5 6 7 4 0 8 9
//1 4 June 8 July 3 2 0 5 9
//1 5 6, 3, 4, 0 2 7 8 9
//1 June 5 4 0 July 3 2 8 9
//1, 7, 4, 5, 8 and 9 6 0, 2, 3,
//1 2 3 4 5 6 7 8 9 0
//1 2 3 4 5 6 7 8 9 0
//2 0 1, 3, 4, 5 6 7 8 9
//2 1 9 3 4 6 7 5 8 0
//2 0 8 1 9 5 6 7 4 3
//2, 3, 7 0 5 6 4 1 8 9
//2 4 June 8 July 3 0 1 5 9
//2, 6, 3, 4, 5 1 0 7 8 9
//2 June 5 4 1 July 3 0 8 9
//2, 7, 4, 5, 8 and 9 June 1 0 3
//2 3 4 5 6 7 8 0 1 9
//8, 9, 0 2 3 4 5 6 7 1
//3 1 2 0 4 5 6 7 8 9
//1 9 3 4 6 7 0 5 8 2
//3 2 1, 5 8 9 6 7 4 0
//3 0 2 5 6 7 4 1 8 9
//2, 3, 4, 6 8 7 0 1 9 5
//3 5 6 0 4 1 2 7 8 9
//3 4 5 6 7 1 0 2 8 9
//3, 7, 4, 5, 8 and 9 June 1 2 0
//3 8 0 5 6 7 4 2 1 9
//3 9 2 8 7 0 6,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, 5 0 9 6 1 2 3
//8 0 1 2 3 4 5 6 7 9
//8 9 2 0 3 4 5 6 7 1
//9 1 2 3 4 5 6 7 8 0
//9 1 0 3 4 6 7 8 2 5
//9 2 1, 5 8 0 6 7 4 3
//9 3 2 5 6 7 4 1 8 0
//9 June 8 July 1 2 3 4 5 0
//9 5 6 7 1 2 3 4 8 0
//9 June 5 4 1 July 3 2 8 0
//9 7, 4, 5, 8 0 6 1 2 3
//0 1 2 3 4 5 6 7 8 9
//9 0 2 3 4 5 6 7 8 1
//total count: 3628800
//OKcount: 0
//

CodePudding user response:

Three sheep in delight issue is what
Doesn't even have a link to
To answer your question have to search on my own question?

CodePudding user response:

The
reference 3 floor lin5161678 response:
three sheep in delight issue is what
Doesn't even have a link to
To answer your question have to search on my own question?

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related