北京大學複試上級題
給一個由不同小寫字母組成的字符串,輸出字符串的全排列。
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
char str[10001];
void Permutation(int from,int to)
{
if(from==to)
{
for(int i=0;i<=to;i++)
{
cout<<str[i];
}
cout<<'\n';
return;
}
for(int i=from;i<=to;i++)
{
swap(str[i],str[from]);//交換
Permutation(from+1,to);
swap(str[i],str[from]);//還原
}
}
int main()
{
cin>>str;
int size =strlen(str);
Permutation(0,size-1);
return 0;
}