字符串的全排列(包括去重)
#include<iostream>
#include<stdio.h>
using namespace std;
int take[4]={0};
int flag[4]={0};
char word[]="boy";
void Try (int i)
{
int j,k;
for(j=1;j<=3;j++)
{
if(flag[j]!=0) continue;
for(k=1;k<j;k++){
if(flag[k]==0){
if(word[j-1]==word[k-1])
break;
}
}
if (k<j) continue;
take[i]=j;
flag[j]=1;
if(i==3)
{
for(k=1;k<4;k++ )
{cout<<word[take[k]-1];
}
cout<<endl;
}
else{
Try(i+1);
}
flag[j]=0;
take[i]=0;
}
}
int main()
{
Try(1);
}