/*next_permutation()返回的是布尔类型*/
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string str;
cin>>str;
sort(str.begin(),str.end());
cout<<str<<endl;
while(next_permutation(str.begin(),str.end()))
{
cout<<str<<endl;
}
return 0;
}
/*使用大数据测试的时候,发现标准C++的效率很差,换成C写效率将快一倍多*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int length;
char str[100];
gets(str);
length=strlen(str);
sort(str,str+length);
puts(str);
while(next_permutation(str,str+length))
{
puts(str);
}
return 0;
}
next_permutation()的函数原理如下:
template<class BidirectionalIterator>
bool next_permutation(
BidirectionalIterator _First,
BidirectionalIterator _Last
);
template<class BidirectionalIterator, class BinaryPredicate>
bool next_permutation(
BidirectionalIterator _First,
BidirectionalIterator _Last,
BinaryPredicate _Comp
);