プログラミング道場 ACM/ICPC

順列を作成する

最終更新:

kit

- view
メンバー限定 登録/ログイン

順列を簡単に作成する


ベクターや配列の要素を並び替えて順列を作ります.

#include <iostream>
#include <algorithm>
#define N 5

int a[N] = {1, 2, 3, 4, 5};

using namespace std;

int main()
{
  //aは初期状態においてソートされている必要がある
  do
  {
    for (int i = 0; i < N; i++)
    {
      cout << a[i] << " ";
    }
    cout << endl;
  }
  while ( next_permutation( a, a+N ) );

  return 0;
}
ウィキ募集バナー