码迷,mamicode.com
首页 > 其他好文 > 详细

51Nod 1384 全排列

时间:2018-10-09 00:43:15      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:begin   pac   排列   code   结果   include   stl   queue   cstring   

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 ;
}

51Nod 1384 全排列

标签:begin   pac   排列   code   结果   include   stl   queue   cstring   

原文地址:https://www.cnblogs.com/Cantredo/p/9757964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!