• 求全排列,调用C++函数



                                                      C - Orders
    Time Limit:1000MS    Memory Limit:10000KB    64bit IO Format:%I64d & %I64u

    Description

    The stores manager has sorted all kinds of goods in an alphabetical order of their labels. All the kinds having labels starting with the same letter are stored in the same warehouse (i.e. in the same building) labelled with this letter. During the day the stores manager receives and books the orders of goods which are to be delivered from the store. Each order requires only one kind of goods. The stores manager processes the requests in the order of their booking.

    You know in advance all the orders which will have to be processed by the stores manager today, but you do not know their booking order. Compute all possible ways of the visits of warehouses for the stores manager to settle all the demands piece after piece during the day.

    Input

    Input contains a single line with all labels of the requested goods (in random order). Each kind of goods is represented by the starting letter of its label. Only small letters of the English alphabet are used. The number of orders doesn't exceed 200.

    Output

    Output will contain all possible orderings in which the stores manager may visit his warehouses. Every warehouse is represented by a single small letter of the English alphabet -- the starting letter of the label of the goods. Each ordering of warehouses is written in the output file only once on a separate line and all the lines containing orderings have to be sorted in an alphabetical order (see the example). No output will exceed 2 megabytes.

    Sample Input

    bbjd
    

    Sample Output

    bbdj
    bbjd
    bdbj
    bdjb
    bjbd
    bjdb
    dbbj
    dbjb
    djbb
    jbbd
    jbdb
    jdbb
    


    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    #include<iostream>
    using namespace std;
    
    int main()
    {
        char s[1000];
        int len;
    
        while(gets(s)!=NULL)
        {
            len = strlen(s);
            sort(s, s+len);//先对字符串进行由小到大排序
           do
           {
                puts(s);
           }
            while(next_permutation(s, s+len));
        }
        return 0;
    }
    

    知识点:

             next_permutation  函数:  这是一个求一个排序的下一个排列的函数,可以遍历全排列, 要包含头文件<algorithm>

            比如:输入 acb

                    然后: 依次输出数列的顺序就会为   。 STL 果然强大。。。。。。

    每天训练发现我比别人做的好慢,但是理解的更深刻,如果一开始学一个新知识点就搜模板,那么这样的人是走不远的,毕业之后带走的只有思维,什么荣誉,奖杯都已经不重要了。
  • 相关阅读:
    游戏引擎中的光照算法
    深入剖析GPU Early Z优化
    UE4联机编译光照
    深入剖析MSAA
    Unity 使用xLua遇到的坑
    扩展SQLite使其能从apk文件中读取db
    tolua#代码简要分析
    虚幻4垃圾回收剖析
    虚幻4蓝图虚拟机剖析
    java转成xml
  • 原文地址:https://www.cnblogs.com/6bing/p/3931235.html
Copyright © 2020-2023  润新知