#include<stdio.h>
#include<iomanip>
#include<iostream>
#include<cstring>
using namespace std;
int goback(int);int a[6][6]={{0},{0,0,1,1},{1,1,0,0,1},{0,1,1},{1,1,0,1},{0,1,0,0,1}};
int er=0;
char result[6]={0};int book[6];
int print()
{
er++;
cout<<"answer "<<er<<":\n";
for (int c=1;c<=5;c++)
printf("%d ",result[c]+64);
cout<<endl;
}
int goback (int z)
{
//int k=1;
if (z==5)
print();
for (int k=1;k<=5;k++)
{
if (a[z][k]&&!book[k])
{
book[k]=1;
result[z]=k;
if (z==5)
print();
else goback(z+1);
book[k]=0;result[z]=0;
}
}
}
int main()
{
memset (book,0,6*sizeof(int));
goback(1);
return 0;
}
选书的函数在238也页
时间: 2024-10-29 00:26:15