标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5634 Accepted Submission(s): 2159
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 using namespace std; 6 int main() 7 { 8 int a, b, c, d, num[4], deal[25], j = 0; 9 while(~scanf("%d %d %d %d", &a, &b, &c, &d), a+b+c+d) 10 { 11 if(j != 0) 12 printf("\n"); 13 int m = 0; 14 num[0] = a; num[1] = b; num[2] = c; num[3] = d; 15 for(int i = 0; i < 4; i++) 16 for(int j = 0; j < 4; j++) 17 for(int k = 0; k < 4; k++) 18 for(int l = 0; l < 4 ; l++) 19 if(num[i] != 0 && i != j && i != k && i != l && j != k && j != l && k != l) //24种组合方式。 20 deal[m++] = num[i]*1000 + num[j]*100 + num[k]*10 + num[l]; 21 // printf("%d\n", m); 22 23 sort(deal, deal + m); 24 int ti = deal[0]; 25 for(int i = 1; i < m; i++) //去重; 26 { 27 if(deal[i] == ti) 28 deal[i] = 0; 29 else 30 ti = deal[i]; 31 } 32 int temp = deal[0]/1000; 33 printf("%d", deal[0]); 34 for(int i = 1; i < m; i++) 35 { 36 if(!deal[i]) 37 continue; 38 if(deal[i]/1000 == temp) 39 printf(" %d", deal[i]); 40 else 41 { 42 temp = deal[i] / 1000; 43 printf("\n"); 44 printf("%d", deal[i]); 45 } 46 } 47 printf("\n"); 48 j++; 49 } 50 return 0; 51 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4725356.html