zoukankan      html  css  js  c++  java
  • 字典比较,下一排列组合,上一排列组合

    题目描述:

    输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。

    输入:

    每个测试案例包括1行。

    输入一个字符串,长度不超过9(可能有字符重复),字符只包括大小写字母。

    输出:

    对应每组数据,按字典序输出所有排列。

    样例输入:
    abc BCA 
    样例输出:
    abc acb bac bca cab cba ABC ACB BAC BCA CAB CBA

    #include <iostream>
    #include <string>
    #include <stdio.h>
    #include <algorithm>

    using namespace std;

    int main()
    {
        string str;
        while(cin>>str)
        {
            sort(str.begin(),str.end());
            string tmp(str);
            do
            {
                //cout<<tmp<<endl;
                printf("%s\n",tmp.c_str());  //用printf()纯粹是为了提高打印速度.
                /*
                next_permutation(tmp.begin(),tmp.end());下一排列组合.
                prev_permutation(tmp.begin(),tmp.end());上一排列组合.

                */
                next_permutation(tmp.begin(),tmp.end());
            }while(lexicographical_compare(str.begin(),str.end(),tmp.begin(),tmp.end()));
            //字典比较.
        }
        return 0;
    }

  • 相关阅读:
    poj 3111 卖珠宝问题 最大化平均值
    如何在b站上传高码率视频
    AC自动机总结
    NOIP2018 旅行
    NOI2008 假面舞会 DFS
    鸽子的记录
    Unity学习笔记
    LuoguP1196 [NOI2002]银河英雄传说 并查集
    Luogu1801 黑匣子 堆
    Luogu P1321 单词覆盖还原 字符串
  • 原文地址:https://www.cnblogs.com/wmx3ng/p/2775955.html
Copyright © 2011-2022 走看看