zoukankan      html  css  js  c++  java
  • 九个数的全排列(避免重复出现)

    题意:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1384

    使用标准库里面的next_permutation()函数,这个函数是生成所有比当前的字符串大的字符串,所以最开始经过sort()排序之后,要先打印出当前的字符串。
    C++ STL中提供了std::next_permutation与std::prev_permutation可以获取数字或者是字符的全排列,其中std::next_permutation提供升序、std::prev_permutation提供降序。

    两个代码本质是一样的  一个从字符串出现,一个从数组

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<map>
    #include<vector>
    #include<math.h>
    #include<string>
    #include<numeric>
    using namespace std;
    #define INF 0x3f3f3f3f
    #define LL long long
    #define N 106
    #define Lson rood<<1
    #define Rson rood<<1|1
    int main()
    {
        char s[21];
        scanf("%s", s);
        int lenth = strlen(s);
        std::sort(s, s + lenth);///将字符串按照字典数排序
        printf("%s
    ", s);///生成所有比当前的字符串大的字符串
        while (std::next_permutation(s, s + lenth))
            printf("%s
    ",s);
        return 0;
    }

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    int main()
    {
        char s[10];
        int a[10];
        scanf("%s",s);
        for(int i=0; s[i]!=''; i++)
            a[i]=s[i]-'0';
        int l=strlen(s);
        sort(a,a+l);
        for(int i=0; i<l; i++)
                printf("%d",a[i]);
            printf("
    ");
        while(next_permutation(a,a+l))
        {
            for(int i=0; i<l; i++)
                printf("%d",a[i]);
            printf("
    ");
        }
        return 0;
    
    }
  • 相关阅读:
    windows的端口映射
    windows的ics
    关于windows的右键菜单项 注册表删除
    dig的使用 openwrt
    linux环境变量相关
    Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1
    openwrt ipv6
    ros资料参考
    ipv6的相关参考资料
    supervisor
  • 原文地址:https://www.cnblogs.com/a719525932/p/7839685.html
Copyright © 2011-2022 走看看