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