标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7151 Accepted Submission(s): 2723
1 //2016.8.30 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <set> 7 8 using namespace std; 9 10 int a[4], vis[4], ans[4]; 11 set<int> s; 12 13 void dfs(int step) 14 { 15 if(step == 4) 16 { 17 int tmp = 1000*ans[0]+100*ans[1]+10*ans[2]+ans[3]; 18 s.insert(tmp); 19 return ; 20 } 21 for(int i = 0; i < 4; i++) 22 { 23 if(step == 0 && a[i] == 0)continue; 24 if(vis[i])continue; 25 vis[i] = 1; 26 ans[step] = a[i]; 27 dfs(step+1); 28 vis[i] = 0; 29 } 30 } 31 32 int main() 33 { 34 int pre; 35 while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])) 36 { 37 if(!a[0]&&!a[1]&&!a[2]&&!a[3])break; 38 s.clear(); 39 sort(a, a+4); 40 memset(vis, 0, sizeof(vis)); 41 dfs(0); 42 for(set<int>::iterator it = s.begin(); it != s.end(); it++) 43 { 44 int tmp = *it; 45 if(it==s.begin()){ 46 cout<<tmp; 47 pre = tmp/1000; 48 }else 49 { 50 if(tmp/1000 == pre)cout<<" "<<tmp; 51 else { 52 cout<<endl<<tmp; 53 pre = tmp/1000; 54 } 55 } 56 } 57 cout<<endl<<endl; 58 } 59 60 return 0; 61 }
标签:
原文地址:http://www.cnblogs.com/Penn000/p/5823879.html