【HDOJ】1716 排列2
STL。
1 /* 1716 */ 2 #include <iostream> 3 #include <algorithm> 4 #include <cstdio> 5 #include <cstring> 6 using namespace std; 7 8 #define MAXN 30 9 int b[MAXN]; 10 11 int main() { 12 int a[4]; 13 int t = 0, n; 14 int i, j, k; 15 16 #ifndef ONLINE_JUDGE 17 freopen("data.in", "r", stdin); 18 freopen("data.out", "w", stdout); 19 #endif 20 21 while (1) { 22 j = 0; 23 for (i=0; i<4; ++i) { 24 scanf("%d", &a[i]); 25 j += a[i]; 26 } 27 if (j == 0) 28 break; 29 if (t++) 30 printf("\n"); 31 sort(a, a+4); 32 n = 0; 33 do { 34 if (a[0]) { 35 b[n++] = 1000*a[0]+100*a[1]+10*a[2]+a[3]; 36 } 37 } while (next_permutation(a, a+4)); 38 b[n] = 0; 39 for (i=0; i<n; ++i) { 40 j = b[i]/1000; 41 k = b[i+1]/1000; 42 if (j == k) 43 printf("%d ", b[i]); 44 else 45 printf("%d\n", b[i]); 46 } 47 } 48 49 return 0; 50 }