Fancy Mouse
- -|||
经典的递归题。一层递归确定一个字母,第一层确定第一个字母。而确定字母是通过字符交换来实现排列的~~说的晦涩了一些,看代码吧:
#include<iostream>
using namespace std;

void Permulate(char s[],int start,int all);
void Copy(char a[],char b[],int i);
int main()
{
    
char s[10];
    cin
>>s;
    
int temp=0;
    
while(s[temp]) temp++;
    Permulate(s,
0,temp);
    
return 0;
}

void Copy(char a[],char b[],int i)
{
    
for(int m=0;m<i;m++)
        b[m]
=a[m];
}

void Permulate(char s[],int start,int all)
{
    
int temp=0;
    
if(start==all-1)
    
{
        cout
<<s[0];
        
for(temp=1;temp<all;temp++) cout<<' '<<s[temp];
        cout
<<endl;
        
return;
    }

    
char a[10];
    
for(temp=start;temp<all;temp++)
    
{
        
char chr=s[temp];s[temp]=s[start];s[start]=chr;
        Copy(s,a,all);
        Permulate(a,start
+1,all);
    }

}
posted on 2005-08-21 12:02  Fancy Mouse  阅读(737)  评论(2编辑  收藏  举报