| ||||||||||
| 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 | |||||||||
请高手帮忙看看哪错了import java.util.Scanner;
public class Main{
static int[][] r;
static char[][] end;
static boolean[][] judge;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
for(int i=1;;i++)
{
int n=in.nextInt();
if(n==0)
return;
r=new int[n][n];
end=new char[4*n-3][4*n+1];
judge=new boolean[4*n-3][4*n+1];
for(int j=0;j<n;j++)
for(int k=0;k<n;k++)
r[j][k]=in.nextInt();
for(int j=0;j<4*n-3;j++)
for(int k=0;k<4*n+1;k++)
{
end[j][k]=' ';
judge[j][k]=true;
}
for(int j=0;j<4*n-3;j+=4)
for(int k=2;k<4*n+1;k+=4)
end[j][k]='O';
for(int j=0;j<4*n-3;j+=4)
for(int k=0;k<4*n+1;k+=4)
end[j][k]='H';
for(int j=2;j<4*n-3;j+=4)
for(int k=2;k<4*n+1;k+=4)
end[j][k]='H';
if(r[0][0]==0)
{
end[0][1]='-';
end[1][2]='|';
judge[0][0]=false;
judge[2][2]=false;
}
if(r[0][n-1]==0)
{
end[0][4*n-1]='-';
end[1][4*n-2]='|';
judge[0][4*n]=false;
judge[2][4*n-2]=false;
}
if(r[n-1][0]==0)
{
end[4*n-4][1]='-';
end[4*n-5][2]='|';
judge[4*n-4][0]=false;
judge[4*n-6][2]=false;
}
if(r[n-1][n-1]==0)
{
end[4*n-4][4*n-1]='-';
end[4*n-5][4*n-2]='|';
judge[4*n-4][4*n]=false;
judge[4*n-6][4*n-2]=false;
}
for(int j=0;j<n;j++)
for(int k=0;k<n;k++)
{
if(r[j][k]==1)//O[4*j][2+4*k]
{
end[4*j][1+4*k]='-';
end[4*j][3+4*k]='-';
judge[4*j][4*k]=false;
judge[4*j][4+4*k]=false;
continue;
}
if(r[j][k]==-1)
{
end[4*j-1][2+4*k]='|';
end[4*j+1][2+4*k]='|';
judge[4*j-2][2+4*k]=false;
judge[4*j+2][2+4*k]=false;
}
}
for(int j=0;j<n;j++)
for(int k=0;k<n;k++)
{
if(r[j][k]==0)//O[4*j][2+4*k]
{
if(j==0&&k==0)
continue;
if(j==0&&k==n-1)
continue;
if(j==n-1&&k==0)
continue;
if(j==n-1&&k==n-1)
continue;
int count=0;
if(4*j-1>=0&&judge[4*j-2][2+4*k])
{
end[4*j-1][2+4*k]='|';
judge[4*j-2][2+4*k]=false;
count++;
}
if(1+4*k>=0&&judge[4*j][4*k])
{
end[4*j][1+4*k]='-';
judge[4*j][4*k]=false;
count++;
}
if(count==2)
continue;
if(3+4*k<=4*n&&judge[4*j][4+4*k])
{
end[4*j][3+4*k]='-';
judge[4*j][4+4*k]=false;
count++;
}
if(count==2)
continue;
if(4*j+1<4*n-3&&judge[4*j+2][2+4*k])
{
end[4*j+1][2+4*k]='|';
judge[4*j+2][2+4*k]=false;
count++;
}
}
}
System.out.println("Case "+i+":\n");
for(int j=0;j<4*n+3;j++)
System.out.print("*");
System.out.println();
for(int j=0;j<4*n-3;j++)
{
System.out.print("*");
for(int k=0;k<4*n+1;k++)
System.out.print(end[j][k]);
System.out.println("*");
}
for(int j=0;j<4*n+3;j++)
System.out.print("*");
System.out.println("\n");
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator