水题1099之Square Ice

Square Ice
Time Limit:1000MS Memory Limit:10000K
Total Submissions:3450 Accepted:1355

Description

Square Ice is a two-dimensional arrangement of water molecules H2O, with oxygen at the vertices of a square lattice and one hydrogen atom between each pair of adjacent oxygen atoms. The hydrogen atoms must stick out on the left and right sides but are not allowed to stick out the top or bottom. One 5 x 5 example is shown below.

Note that each hydrogen atom is attached to exactly one of its neighboring oxygen atoms and each oxygen atom is attached to two of its neighboring hydrogen atoms. (Recall that one water molecule is a unit of one O linked to two H's.)

It turns out we can encode a square ice pattern with what is known as an alternating sign matrix (ASM): horizontal molecules are encoded as 1, vertical molecules are encoded as -1 and all other molecules are encoded as 0. So, the above pattern would be encoded as:

An ASM is a square matrix with entries 0, 1 and -1, where the sum of each row and column is 1 and the non-zero entries in each row and in each column must alternate in sign. (It turns out there is a one-to-one correspondence between ASM's and square ice patterns!)

Your job is to display the square ice pattern, in the same format as the example above, for a given ASM. Use dashes (-) for horizontal attachments and vertical bars (|) for vertical attachments. The pattern should be surrounded with a border of asterisks (*), be left justified and there should be exactly one character between neighboring hydrogen atoms (H) and oxygen atoms (O): either a space, a dash or a vertical bar.

Input

Input consists of multiple cases. Each case consists of a positive integer m (<= 11) on a line followed by m lines giving the entries of an ASM. Each line gives a row of the ASM with entries separated by a single space. The end of input is indicated by a line containing m = 0.

Output

For each case, print the case number (starting from 1), in the format shown in the Sample Output, followed by a blank line, followed by the corresponding square ice pattern in the format described above. Separate the output of different cases by a blank line.

Sample Input

2
0 1
1 0
4
0 1 0 0
1 -1 0 1
0 0 1 0
0 1 0 0
0

Sample Output

Case 1:

***********
*H-O H-O-H*
*  |      *
*  H   H  *
*      |  *
*H-O-H O-H*
***********

Case 2:

*******************
*H-O H-O-H O-H O-H*
*  |       |   |  *
*  H   H   H   H  *
*      |          *
*H-O-H O H-O H-O-H*
*      |   |      *
*  H   H   H   H  *
*  |           |  *
*H-O H-O H-O-H O-H*
*      |          *
*  H   H   H   H  *
*  |       |   |  *
*H-O H-O-H O-H O-H*
*******************
#include<iostream>
using namespace std;
#define NUMMAX 100
#define MMAX 15
char arr[NUMMAX][NUMMAX];
int ASM[MMAX][MMAX];
int main(){
	int M,i,j,k=1;
	while(true){
		cin>>M;
		for(i=1;i<=M;i++)
			for(j=1;j<=M;j++)
				cin>>ASM[i][j];
		for(i=1;i<=4*M-1;i++){
			for(j=1;j<=4*M+3;j++){
				if(i==1||i==4*M-1){
					arr[i][j]='*';
				}else{
					if(j==1||j==4*M+3)
						arr[i][j]='*';
					else if(i%4==0){
						if(j%4==0)
							arr[i][j]='H';
						else
							arr[i][j]=' ';
					}
					else if(i%4==2){
						if(j%4==2)
							arr[i][j]='H';
						else if(j%4==0)
							arr[i][j]='O';
						else 
							arr[i][j]=' ';
					}
					else if(i%2==1){
						arr[i][j]=' ';
					}
				}
			}
		}


		for(i=1;i<=M;i++){
			for(j=1;j<=M;j++){
					if(ASM[i][j]==0){
						if(j==1){
							arr[4*i-2][3]='-';
						}else{
							if(arr[4*i-2][j*4-3]==' ')
								arr[4*i-2][j*4-1]='-';
							else
								arr[4*i-2][j*4+1]='-';
						}

						if(i==1){
							arr[3][4*j]='|';
						}else{
							if(arr[4*i-5][4*j]=='|')
								arr[4*i-1][4*j]='|';
							else
								arr[4*i-3][4*j]='|';
						}
					}else if(ASM[i][j]==1){
						arr[4*i-2][4*j-1]='-';
						arr[4*i-2][4*j+1]='-';
					}else if(ASM[i][j]==-1){
						arr[4*i-3][4*j]='|';
						arr[4*i-1][4*j]='|';
					}
			}
		}
		cout<<endl<<"Case "<<k++<<":"<<endl<<endl;;
		for(i=1;i<=4*M-1;i++){
			for(j=1;j<=4*M+3;j++)
				cout<<arr[i][j];
			cout<<endl;
		}
		cout<<endl;
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值