美文网首页
poj1256 全排列(STL)

poj1256 全排列(STL)

作者: 暖昼氤氲 | 来源:发表于2019-11-08 13:57 被阅读0次
/*
Time:2019.11.7
Author: Goven
type:全排列 (STL)
err:
ref:
知识点:bool next_permutation(start_pos, end_pos, cmp(可自定义))---同sort 
*/
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
bool cmp (char a, char b) {
    if (a + 32 == b || a - 32 == b) return a < b;
    return tolower(a) < tolower(b);
}

int main()
{
    int n;
    string str;
    cin >> n;
    while (n--) {
        cin >> str;
        sort(str.begin(), str.end(), cmp);
        cout << str << endl;
        while (next_permutation(str.begin(), str.end(), cmp)) {//err1:需要重新定义cmp函数 
            cout << str << endl;
        }
    } 
    return 0;
}


相关文章

  • poj1256 全排列(STL)

  • 递归-全排列

    对数组{1,2,3}进行全排列 STL next_permutation

  • poj1146 全排列(STL)

  • 使用C++ STL的next/prev_permutation函

    使用C++ STL的next_permutation函数可以简单的枚举出一个升序排列的字符串的全排列,它包含在头文...

  • 全排列生成算法 next_permutation

    概念 全排列的生成算法有很多种,有递归遍例,也有循环移位法等等。C++/STL中定义的next_permutati...

  • 全排列

    例:对{1,2,3,4}的全排列输出。 笔试中遇到了,之前在STL中见过现成的函数,也有实现方法,但是笔试时想不起...

  • 《算法竞赛入门经典》第七章学习笔记

    枚举排列 生成1~n的排列 生成可重集的排列 利用STL生成排列 子集生成 增量构造法 位向量法 二进制法

  • 全排列与字典序

    全排列 递归实现全排列; 首先来说递归算法实现全排列: 例如,对于{1,2,3,4}的例子进行全排列,其可以分解...

  • 全排列问题

    中午看到的一个题目。求一个不重复字符串的全排列。 主要有递归,字典序等解决方案。然后想到stl里的next_per...

  • 全排列

    求全排列最简单的就是递归了123 的全排列共有 6 个, 123 的全排列等于以 1 开头 23 的全排列, 加上...

网友评论

      本文标题:poj1256 全排列(STL)

      本文链接:https://www.haomeiwen.com/subject/ahgibctx.html