题意:将给出的序列的全排列输出。
题解:先将给出的序列按字典序排序,然后从这个序列开始,用next_permutation(),将所有的下一个排列输出。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main() {
int n;
char s[15];
scanf("%d", &n);
while (n--) {
scanf("%s", s);
sort(s, s + strlen(s));
do {
for (int i = 0; i < strlen(s); i++)
printf("%c", s[i]);
printf("\n");
}while (next_permutation(s, s + strlen(s)));
printf("\n");
}
return 0;
}