回覆列表
  • 1 # 藍風24

    #include

    #include

    #include

    int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    int b[5], rank[5];

    bool used[10] = {false};

    bool p_used[5] = {false};

    void Permutation(int deep);

    void main()

    {

    int i = 0, j = 0, k = 0, temp;

    srand((unsigned)time(NULL));

    for(i = 0; i

    {

    temp = rand()%9;

    for(k = 0; k

    {

    if(a[k] == temp)

    {

    if(used[k] == false)

    {

    b[j++] = temp;

    used[k] = true;

    break;

    }

    else

    {

    i--;

    break;

    }

    }

    }

    }

    Permutation(0);

    printf("\n");

    }

    void Permutation(int deep)

    {

    int i;

    if(deep == 5)

    {

    printf("%d %d %d %d %d\n",b[rank[0]], b[rank[1]], b[rank[2]], b[rank[3]], b[rank[4]]);

    }

    for(i = 0; i

    {

    if(p_used[i] == true)

    continue;

    p_used[i] = true;

    rank[deep] = i;

    Permutation(deep + 1);

    p_used[i] = false;

    }

    }

  • 中秋節和大豐收的關聯?
  • 二0一四年九月三十日搬家可以嗎?