51nod1384 全排列


1384全排列
基准时间限制:1秒 空间限制:131072KB 分值:0难度:基础题
收藏
关注
给出一个字符串S(可能有重复的字符),按照字典序从小到大,输出S包括的字符组成的所有排列。例如:S = "1312", 输出为:
1123 1132 1213 1231 1312 1321 2113 2131 2311 3112 3121 3211
Input
输入一个字符串S(S的长度<=9,且只包括0-9的阿拉伯数字)
Output
输出S所包含的字符组成的所有排列
Input示例
1312
Output示例
1123
1132
1213
1231
1312
1321
2113
2131
2311
3112
3121
3211


题意:中文题!

思路:把string转成char数组,采用next_permutation(iterator start,iterator end);函数求解,头文件#include<algorithm>


#include <iostream>
#include<string>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=10;
char ch[maxn];
int main()
{
    string str;
    cin>>str;
    int len=str.length();
    for(int i=0;i<len;i++)
    {
        ch[i]=str[i];
    }
    sort(ch,ch+len);
    do
    {
        for(int i=0;i<len;i++)
            cout<<ch[i];
        cout<<endl;
    }while(next_permutation(ch,ch+len));
    return 0;
}


优质内容筛选与推荐>>
1、張忠謀:我工作,所以我存在
2、buy or not buy
3、第四十章 远方的消息d
4、Hibernate之mappedBy
5、QT5 - 数据库、QMYSQL driver not loaded


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn