1个回答
展开全部
#include<stdio.h>
#define M 100 //a stand for'-'
int n=4; //b stand for'/'
main() //c stand for'\'
{int a[M]={0},b[M]={0},c[M]={0},g[M]={0};
int i=0,j=0,k=0,x,flag=0,z=1;
FILE * out;
out=fopen("out.txt","w");
while(i<n)
{g[j]=i;
a[i]=1;
b[i]=1;
c[n-1-i]=1;
k=0;
j=1;
printf("1 a%d b%d c%d\n",i,i,n-1-i);
// system("pause");
while(j>0&&j<n)
{while(k<n)
{if(a[k]==1||b[k+j]==1||c[n-1-k+j]==1)
{if(k==n-1){flag=1;break;}
else {k++;continue;}
}
g[j]=k;
if(j==n-1)
{printf("第%d种:",z++);
for(x=0;x<n;x++)
{printf("%d ",g[x]);
fprintf(out,"%-3d",g[x]);
}
fprintf(out,"\n");
printf("\n");
//system("pause");
k++;
continue;}
else
{a[k]=1;
b[k+j]=1;
c[n-1-k+j]=1;
printf("2 a%d b%d c%d\n",k,k+j,n-1-k+j);
// system("pause");
flag=0;
break;}
}
if(flag==1)
{j--;
if(j==0)
{a[i]=0;
b[i]=0;
c[n-1-i]=0;
printf("4 a%d b%d c%d\n",i,i,n-1-i);
i++;
break;
}
a[g[j]]=0;
b[g[j]+j]=0;
c[n-1-g[j]+j]=0;
printf("3 a%d b%d c%d\n",g[j],g[j]+j,n-1-g[j]+j);
// system("pause");
g[j]++;
k=g[j];
}
else//flag==0
{j++;
k=0;}
}
}
fclose(out);
}
//fprintf(out,"\n");
//fprintf(out,"第%d种:",z++);
//fprintf(out,"%-3d",g[x]+1);
//system("pause");
#define M 100 //a stand for'-'
int n=4; //b stand for'/'
main() //c stand for'\'
{int a[M]={0},b[M]={0},c[M]={0},g[M]={0};
int i=0,j=0,k=0,x,flag=0,z=1;
FILE * out;
out=fopen("out.txt","w");
while(i<n)
{g[j]=i;
a[i]=1;
b[i]=1;
c[n-1-i]=1;
k=0;
j=1;
printf("1 a%d b%d c%d\n",i,i,n-1-i);
// system("pause");
while(j>0&&j<n)
{while(k<n)
{if(a[k]==1||b[k+j]==1||c[n-1-k+j]==1)
{if(k==n-1){flag=1;break;}
else {k++;continue;}
}
g[j]=k;
if(j==n-1)
{printf("第%d种:",z++);
for(x=0;x<n;x++)
{printf("%d ",g[x]);
fprintf(out,"%-3d",g[x]);
}
fprintf(out,"\n");
printf("\n");
//system("pause");
k++;
continue;}
else
{a[k]=1;
b[k+j]=1;
c[n-1-k+j]=1;
printf("2 a%d b%d c%d\n",k,k+j,n-1-k+j);
// system("pause");
flag=0;
break;}
}
if(flag==1)
{j--;
if(j==0)
{a[i]=0;
b[i]=0;
c[n-1-i]=0;
printf("4 a%d b%d c%d\n",i,i,n-1-i);
i++;
break;
}
a[g[j]]=0;
b[g[j]+j]=0;
c[n-1-g[j]+j]=0;
printf("3 a%d b%d c%d\n",g[j],g[j]+j,n-1-g[j]+j);
// system("pause");
g[j]++;
k=g[j];
}
else//flag==0
{j++;
k=0;}
}
}
fclose(out);
}
//fprintf(out,"\n");
//fprintf(out,"第%d种:",z++);
//fprintf(out,"%-3d",g[x]+1);
//system("pause");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询