参考
http://blog.youkuaiyun.com/jiejinquanil/article/details/52164086
关键点
sort(vs.begin(),vs.end());
reverse(vs.begin(),vs.end());
- #include<iostream>
- #include<string>
- #include<vector>
- using namespace std;
- void Permutation(string *s,int len)
- {
- if(len == (*s).length())
- cout<<(*s)<<endl;
- else
- {
- for(int i = len;i<(*s).length();++i)
- {
- swap((*s)[len],(*s)[i]); // 先对固定位置交换
- Permutation(s,len+1);
- swap((*s)[len],(*s)[i]); // 然后把顺序调回来
- }
- }
- }
- int main()
- {
- string s;
- cin>>s;
- Permutation(&s,0);
- return 0;
- }