Home > Back-end >  Pray god give directions
Pray god give directions

Time:09-19

Time limit: 1 Sec memory limit: 128 MB
Commit: 24 address: 10
[submit] [state] [BBS]

Title description


Two seniors a winter vacation in beer and skittles, still old love pit three senior, as a result, a full array of topics, and for DE Marcia, fighting ~!!! ~,,

What ~! ~ what is full arranged,, look at the data will be understand, the subject a little difficult,,

Enter


A m represents how many sets of data,

Each line within a 9 number n, the output of 1 ~ n permutations


O


Output 1 ~ n permutations have a blank line between each group of data,,

The sample input

3
1
2
3

Sample output

1

12
21

123
132
213
231
312
321



prompt

CodePudding user response:

This problem is not rigorous, is not very good, a good many permutations algorithm, perhaps the result in there will be some differences on the order, so that it can lead to errors, I made a
This is my code, the results and the example above have small differences, but also can find the permutations of n, but this problem is to pass it,
 # include & lt; Bits/stdc++. H> 
using namespace std;
Int a, [10].
int n;
Void dg (int m, int a [])
{
If (m==n)
{
for(int i=1; i<=n; I++)
{
Printf (" % d ", a [I]);
}
printf("\n");
}
For (int I=m; i<=n; I++)
{
Int temp=a, [m].
A [m]=a, [I].
A [I]=temp;
Dg (m + 1, a);
Temp=a, [m].
A [m]=a, [I].
A [I]=temp;
}
}
Int main ()
{
int m;
The scanf (" % d ", & amp; M);
While (m -)
{
Memset (a, 0, sizeof (a));
The scanf (" % d ", & amp; n);
for(int i=1; i<=n; I++)
{
A [I]=I;
}
Dg (1 a);
printf("\n");
}
return 0;
}

this is as a result, there are small differences

CodePudding user response:

STL has a full arrangement function you can try
  • Related