zoukankan      html  css  js  c++  java
  • 索引组合算法原型

    // next_permutation example
    #include <iostream>     // std::cout
    #include <algorithm>    // std::next_permutation, std::sort
    
    int make_combination(int myints[], int start , int end, int requirement_number){
        //std::cout<<"start:"<<start<<"end:"<<end<<"requirement_number:"<<requirement_number<<std::endl;
        if (start == end){
            std::cout << myints[start] << ",";
            requirement_number--;
            if (requirement_number >= 1){
                std::cout << "not ok" << std::endl;
                return 1;
            }else {
                std::cout << std::endl;
                return 0;
            }
        }
        if (1 ==requirement_number){
            requirement_number--;
            std::cout << myints[start] << std::endl;
            return 0;
        }
        std::cout<<myints[start];
        requirement_number--;
        return make_combination(myints, start+1, end, requirement_number );
    }
    
    int main () {
      int myints[] = {1,2,3};
    
      std::sort (myints,myints+3);
      int i =0;
      for(; i<3; i++){
        make_combination(myints, i, 2, 1);
      }
    
    //  std::cout << "The 3! possible permutations with 3 elements:
    ";
    //  do {
    //    std::cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '
    ';
    //  } while ( std::prev_permutation(myints,myints+3) );
    //
    //  std::cout << "After loop: " << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '
    ';
    
      return 0;
    }

     有bug,比如 1,2,3

    只能给出

    1,2

    2,3

    但是看不到

    1,3

    MySQL限时解答,24小时内友哥专业解答
    http://www.yougemysqldba.com
    如有进一步需要请联系微信onesoft007
    微博账号@友哥一指
  • 相关阅读:
    MongoDB 创建数据库
    MongoDB
    MongoDB 概念解析
    window平台安装 MongoDB(二)
    MongoDB入门学习(1)
    解决DevExpress10.2.4版本在VS2012工具箱控件不显示的问题
    Aspose.Word 输出表格后空格字符丢失的解决方法
    ArcEngine 创建空间参考设置默认域
    SPATIALITE 各版本数据库差异
    WGS84投影的WKID说明
  • 原文地址:https://www.cnblogs.com/youge-OneSQL/p/9483578.html
Copyright © 2011-2022 走看看