将1,2,3张排放在3个箱子内,有哪几种排法???
#include<iostream>
using namespace std;
int arr[4], book[3];
void test01(int step)
{
if (step == 4)//箱子已经满了,没有牌可以放了
{
for (int i = 1; i <=3; i++)
{
cout << arr[i] << " " ;//
}
cout << endl;
return;
}
for (int i = 1; i <=3; i++)
{
if(book[i] == 0)//判断牌是否在手中,如果在手中就往下执行
{
arr[step] = i;//将牌放入箱子内
book[i] = 1;//表示这张牌不在手中
test01(step + 1);//继续往箱子里放牌
book[i] = 0;//将牌收回,重新找另外一种排的方法
}
}
}
int main()
{
test01(1);
system("pause");
}