组合算法问题 [英] an combination algorithm question

查看:115
本文介绍了组合算法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个数字:1、2、3.如何编写函数或使用内置函数来获得如下结果:
12
21
13
31
23
31

I have 3 numbers : 1,2,3. How to write an function or use build-in functions to get the result like this:
12
21
13
31
23
31

推荐答案

我希望您能够略微修改置换算法的代码,前提是
I hope you are able to slightly modify the code of permutation algorithm provided here to get the results needed.


#include <iostream>
using namespace std;

int main()
{
  int n[3]={1,2,3};
  for (int i=0; i<3; i++)
  {
    for (int j=1; (j+i) < 3; j++)
    {
      cout << n[i] << n[j+i] << endl;
      cout << n[j+i] << n[i] << endl;
    }
  }
}


这篇关于组合算法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆