标签:include clu tar iss std == ios swap swa
1.递归实现
#include <iostream> #include<stdio.h> #include<string.h> using namespace std; int sum=0; int Isswap(char a[],int start,int end) { for(int i=start;i<end;i++) { if(a[i]==a[end]) return 0; } return 1; } void swap (char a[],int b,int c) { char temp=a[b]; a[b]=a[c]; a[c]=temp; } void quanpai(char a[],int start ,int end) { if (start==end) { for(int i=0;i<=end;i++) cout<<a[i]; cout<<endl; sum++; return; } else { for(int j=start;j<=end;j++) { if(Isswap(a,start,j)) { swap(a, start, j); quanpai(a, start + 1, end); swap(a, j, start); } } } } int main() { char zifu[100]; cin >>zifu; int n=strlen(zifu); quanpai(zifu,0,n-1); cout<<sum<<endl; return 0; }
标签:include clu tar iss std == ios swap swa
原文地址:http://www.cnblogs.com/2014slx/p/7689830.html