zoukankan      html  css  js  c++  java
  • 全排列

    一种全排列是将n个数字放入n个位置里,一种是n个位置上任意位置都可以取0,1,2,...,m,位置之间没有约束

    #include <iostream>
    using namespace std;
    void permutation(char *pStr, char *pBegin, int &count){
        if (*pBegin == ''){
            printf("%s	", pStr);
            count++;
        }else{
            for (char *pCh = pBegin; *pCh != ''; ++pCh){
                
                    char temp1 = *pCh;
                    *pCh = *pBegin;
                    *pBegin = temp1;
                
                permutation(pStr, pBegin + 1,count);
                
                    temp1 = *pCh;
                    *pCh = *pBegin;
                    *pBegin = temp1;
                
            }
        }
    
    }
    int main(){
        char pS[] = "123456";
        int count = 0;
        permutation(pS, pS, count);
        printf("%d", count);
        system("pause");
    }
    //一种是n个位置上任意位置都可以取0,1,2,...,m,位置之间没有约束 #include
    <iostream> using namespace std; void permutation(char *pStr, char *pBegin, int &count){ if (*pBegin == ''){ printf("%s ", pStr); count++; }else{ for (int i = 0; i < 10;i++){ *pBegin = i + '0'; permutation(pStr, pBegin + 1,count); } } } int main(){ const int n = 3; int count = 0; char *pStr = new char[n+1]; pStr[n] = ''; pStr[0] = pStr[1] = pStr[2] = '0'; permutation(pStr, pStr, count); printf("%d ", count); delete[]pStr; system("pause"); }
  • 相关阅读:
    SQLSERVER 远程登录18456错误
    谁用掉了我的数据库空间?
    Zabbix-微信报警
    Mailx安装与使用
    Redis-集群操作
    Redis-集群部署
    十、Zabbix-自动关联模板
    九、Zabbix-触发器
    八、Zabbix-应用集、监控项
    七、Zabbix-模板,应用集,监控项,触发器
  • 原文地址:https://www.cnblogs.com/hzmbbbb/p/3980587.html
Copyright © 2011-2022 走看看