51Nod 1384 全排列

STL的应用。想到全排列就想到了STL中的 next_permutation() 函数。用字符串读取输入,用 sort() 对其进行排序,再用 next_permutation() 输出结果。代码如下:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <utility>
#define ll long long
#define ull_ unsigned long long

using namespace std ;

int main(){
    string str ;
    cin >> str ;
    sort(str.begin() , str.end()) ;
    cout << str << endl ;
    while(next_permutation(str.begin() , str.end())){
        for ( int i = 0 ; i < str.size() ; i ++ ){
            cout << str[i] ;
        }
        cout << endl ;
    }
    return 0 ;
}
posted @ 2018-10-08 23:25  Cantredo  阅读(91)  评论(0)    收藏  举报