The description has 4 distinct numbers and outputs an arrangement of three distinct digits. Input4 an integer. Output all permutations. Sample Input
1 2 3 4
Sample Output
1 2 31 3 22 1 32 3 13 1 23 2 11 2 41 4 22 1 42 4 14 1 24 2 11 3 41 4 33 1 43 4 14 1 34 3 12 3 42 4 33 2 43 4 24 2 34 3 2
HINT
Source
Zjgsu
The code is as follows:
#include <stdio.h>int i,j,k,a[3],b[3],c[3];void Sort (int e[]) {for (i=0; i<3; i++) a[i]=b[i]=c[i]=e[ I]; For (i=0, i<3; i++) {for (j=0; j<3; J + +) {for (k=0; k<3; k++) { if (a[i]==b[j]| | a[i]==c[k]| | B[J]==C[K]) continue; else printf ("%d% d%d\n", A[i],b[j],c[k]);}}} int main () { int i, d[4],e[3]; for (i=0; i<4; i++) scanf ("%d", d+i); E[0]=D[0],E[1]=D[1],E[2]=D[2]; Sort (e); E[0]=D[0],E[1]=D[1],E[2]=D[3]; Sort (e); E[0]=D[0],E[1]=D[2],E[2]=D[3]; Sort (e); E[0]=D[1],E[1]=D[2],E[2]=D[3]; Sort (e); return 0;}
Operation Result:
Learning experience:
Recently trying to use C language to do the problem, but still can not get rid of the thick C + +, often because with some keywords in C + + error.
In fact, this problem is not thought at first, the first reaction is the enumeration, the result that only applies to the case of 1,2,3,4. Then thought of using multiple arrays to save, can be executed perfectly, but still wrong, it actually asked the order,
Thus further complications, which were divided four times at a time. Finally, it's AC.
Ytuoj-c language Experiment-permutation