给定一个字符串,要求你把它的全排列按照字典序的顺序打印出来:
有了algorithm中的next_permutation()函数,则这道题目变得非常水了就……
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
string s;
cin>>s;
sort(s.begin(), s.end());//不要忘记在进入全排列之前先给输入的字符串按照字典序排一下序;
cout<<s<<endl;
while (next_permutation(s.begin(), s.end()))
{
cout<<s<<endl;
}
printf("\n");
}
return 0;
}