最近在网上找到一个巧妙的运用STL生成的排列组合代码。
感觉很好,记之:

 

#include <iostream>
#include 
<algorithm>
#include 
<iterator>

using namespace std;

int main()
{
    
int a[3= {123};
    
do
    {
        copy(a, a 
+ 3, ostream_iterator<int>(cout, " "));
        cout 
<< endl;
    }
while(next_permutation(a, a + 3));

    
return 0;
}

输出结果:

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2021-08-23
  • 2021-10-30
  • 2021-08-24
猜你喜欢
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
相关资源
相似解决方案