首页 > 其他 > 详细

全排列

时间:2017-01-22 12:11:45      阅读:183      评论:0      收藏:0      [点我收藏+]
 1 #include <iostream>
 2 using namespace std;
 3 #define SIZE 6
 4 char data[SIZE]={A,B,C,D,E,F};
 5 char data1[SIZE];
 6 int maxnum=0;
 7 bool safe(char c,int n);
 8 void pailie(int num);
 9 void show();
10 int main()
11 {
12     pailie(0);
13     cout <<maxnum;
14     return 0;
15 }
16 
17 bool safe(char c,int n)
18 {
19     bool ret=true;
20     for(int i=0;i<n;i++)
21     {
22         if(data1[i]==c)
23             ret=false;
24     }
25     return ret;
26 }
27 void pailie(int num)
28 {
29     if(num==SIZE)
30     {
31         show();
32         return;
33     }
34     for(int i=0;i<SIZE;i++)
35     {
36         data1[num]=data[i];
37         if(safe(data1[num],num))
38         {
39             pailie(num+1);
40         }
41     }
42 }
43 
44 
45 void show()
46 {
47     maxnum++;
48     for(int i=0;i<SIZE;i++)
49     {
50         cout <<data1[i];
51     }
52     cout <<"    ";
53     if(maxnum%10==0)
54         cout <<endl;
55 }

 

全排列

原文:http://www.cnblogs.com/jintg/p/6339760.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!