| ||||||||||
| 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 | |||||||||
Re:请高手//赐教 不知道什么地方出错了In Reply To:请高手//赐教 Posted by:minnowlf at 2004-04-18 05:25:51 # include < stdio.h >
# include < stdlib.h >
# include < string.h >
# define MAX 12
int num = 1 ,count = 1;
int a[MAX][MAX];
int tmp[4*MAX-3][4*MAX+1];
//store info in tmp arr: 1--hy,2--ox,3--horizonal ajadent,5--vetical ajadent ,0--' '
void init()
{
int i,j;
for(i=0; i<4*MAX-3; i+=4)
{
for(j=0; j<4*MAX+1;j+=4)
tmp[i][j]=1;
for(j=2;j<4*MAX+1;j+=4)
tmp[i][j]=2;
}
for(i=2;i<4*MAX-3;i+=4)
for(j=2;j<4*MAX+1;j+=4)
tmp[i][j]=1;
}
int valid(int a, int b)
{
if( (a>-1) && (a<4*num-3) && (b>-1) && (b<4*num+1) )
return 1;
return 0;
}
int degree(int a, int b)
{
int sum = 0;
if(valid(a,b-1) && ( tmp[a][b-1] == 3 ))
sum ++;
if(valid(a,b+1) && ( tmp[a][b+1] == 3 ))
sum ++;
if(valid(a-1,b) && ( tmp[a-1][b] == 4 ))
sum ++;
if(valid(a+1,b) && ( tmp[a+1][b] == 4 ))
sum ++;
return sum;
}
void deal()
{
int i,j;
for ( i=0; i<num; i++)
for (j=0; j<num; j++)
{
if (a[i][j] != 0)
{
if(a[i][j] == 1)
tmp[i*4][j*4+1]=tmp[i*4][j*4+3]=3;
else if(a[i][j] == -1)
tmp[i*4-1][j*4+2]=tmp[i*4+1][j*4+2]=4;
}
}
for(i=0; i<4*num-3; i+=2) //deal with horizonal adajent
{
if(i%4==0)
{
for(j=0; j<4*num+1;j+=4)
{
if(degree(i,j)== 0)
{
if( valid(i,j-2) && (degree(i,j-2)!=2) )
tmp[i][j-1]=3;
else if(valid(i,j+2) && (degree(i,j+2))!=2 )
tmp[i][j+1]=3;
}
}
}
else
for(j=2;j<4*num+1;j+=4)
{
if(degree(i,j)==0)
{
if(degree(i-2,j)!=2)
tmp[i-1][j]=4;
else tmp[i+1][j]=4;
}
}
}
}
void my_print(int num)
{
int i,j;
printf("\nCase %d:\n\n",count++);
for(i=0;i<4*num+3;i++)
printf("*");
printf("\n");
for(i=0;i<4*num-3;i++)
{
printf("*");
for(j=0;j<4*num+1;j++)
{
if(tmp[i][j]==1)
printf("H");
else if(tmp[i][j]==2)
printf("O");
else if(tmp[i][j]==3)
{ printf("-");tmp[i][j]=0;}
else if(tmp[i][j]==4)
{ printf("|");tmp[i][j]=0;}
else printf(" ");
}
printf("*\n");
}
for(i=0;i<4*num+3;i++)
printf("*");
printf("\n");
}
int main()
{
int i, j;
scanf ("%d", &num );
init();
while ( num )
{
for ( i=0; i<num; i++)
for (j=0; j<num; j++)
scanf ("%d", &a[i][j]);
deal();
my_print(num);
scanf ("%d",&num );
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator