思路:生成全排列,用next_permutation,注意生成之前先对那个字符数组排序。
AC代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> using namespace std; char str[20]; int main() { int n; cin >> n; while(n--) { scanf("%s", str); int len = strlen(str); sort(str, str + len); do { printf("%s\n", str); }while(next_permutation(str, str + len)); printf("\n"); } return 0; }
UVA - 10098 - Generating Fast (枚举排列)
原文:http://blog.csdn.net/u014355480/article/details/44471361