#include <iostream> #include <string.h> using namespace std; void Swap(char &a, char &b){ char temp; temp = a; a = b; b = temp; } void Perm(char s[], int k){ int n = strlen(s); if(k==n-1){ cout << s << endl; } else{ for(int i=k; i<n; i++){ Swap(s[i], s[k]); Perm(s, k+1); } } } int main() { char str[100]; while(1){ cout << "请输入字符串" << endl; cin >> str; Perm(str, 0); } return 0; }
a - a;ab - ab, ba;
abc- abc, acb, bac, bca, cab, cba.....
一个十分巧妙的递归,输出排列
最新推荐文章于 2022-01-12 21:21:27 发布