| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
没用什么算法,就是一堆迭代,效率低#include<stdio.h>
#include<string.h>
int main()
{
int n,m;
char A[100][100];
int B[12][12],C[13],D[12][12];
int i,j,num,l=0;
while(scanf("%d",&m),m)
{
l++;
for(i=1;i<=m;i++)
for(j=1;j<=m;j++)
scanf("%d",&D[i][j]);
int col=m*4+3,row=4*m-1;
for(i=0;i<col;i++)
{
A[0][i]='*';
A[row-1][i]='*';
}
for(i=1;i<row-1;i++)
{
A[i][0]='*';
A[i][col-1]='*';
}
for(i=2;i<row-1;i=i+2)
for(j=1;j<col-1;j++)
A[i][j]=' ';
for(i=1;i<row-1;i=i+4)
{
for(j=1;j<col-1;j=j+4)
A[i][j]='H';
for(j=2;j<col-1;j=j+2)
A[i][j]=' ';
for(j=3;j<col-1;j=j+4)
A[i][j]='O';
}
for(i=3;i<row-1;i=i+4)
{
for(j=1;j<col-1;j++)
A[i][j]=' ';
for(j=3;j<col-1;j=j+4)
A[i][j]='H';
}
num=0;
memset(B,0,sizeof(B));
for(i=1;i<col-1;i=i+4)
{
num++;
memset(C,0,sizeof(C));
for(j=1;j<=m;j++)
{
if(D[num][j]==0)
{
if(C[j]==0)
{
C[j]=1;
A[i][3+(j-1)*4-1]='-';
B[num][j]++;
}
else
{
C[j+1]=1;
A[i][3+(j-1)*4+1]='-';
B[num][j]++;
}
}
if(D[num][j]==1)
{
A[i][3+(j-1)*4-1]='-';
A[i][3+(j-1)*4+1]='-';
C[j]=1;C[j+1]=1;
B[num][j]=2;
}
}
}
num=0;
for(i=3;i<row-1;i=i+4)
{
num++;
for(j=1;j<=m;j++)
{
if((D[num][j]==0&&B[num][j]==1)||D[num][j]==-1)
{
A[i-1][(j-1)*4+3]='|';
B[num][j]++;
}
else
{
A[i+1][(j-1)*4+3]='|';
B[num+1][j]++;
}
}
}
printf("Case %d:\n\n",l);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
printf("%c",A[i][j]);
printf("\n");
}
printf("\n");
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator