forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1066Square Ice.cpp
More file actions
141 lines (132 loc) · 2.27 KB
/
1066Square Ice.cpp
File metadata and controls
141 lines (132 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
ZJU 1066 Square Ice
00:00.00 440K
2004.07.17 by adai
*/
#include <iostream>
using namespace std;
#define MAXROW 4*11-3
#define MAXCOL 4*11+1
int main()
{
int m,kase(0);
int row,col;
int input[11][11];
char water[MAXROW][MAXCOL];
int i,j;
while(1)
{
cin>>m;
if(m==0) break;
row=4*m-3;
col=4*m+1;
for(i=0;i<m;i++)
{
for(j=0;j<m;j++) cin>>input[i][j];
}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++) water[i][j]=' ';
}
for(i=0;i<row;i+=4)
{
for(j=0;j<col;j+=4) water[i][j]='h';
}
for(i=2;i<row;i+=4)
{
for(j=2;j<col;j+=4) water[i][j]='h';
}
for(i=0;i<row;i+=4)
{
for(j=2;j<col;j+=4) water[i][j]='o';
}
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
if(input[i][j]==1){
water[4*i][4*j+2]='O';
water[4*i][4*j+2-1]=water[4*i][4*j+2+1]='-';
water[4*i][4*j+2-2]=water[4*i][4*j+2+2]='H';
}
else if(input[i][j]==-1)
{
water[4*i][4*j+2]='O';
water[4*i-1][4*j+2]=water[4*i+1][4*j+2]='|';
water[4*i-2][4*j+2]=water[4*i+2][4*j+2]='H';
}
}
}
//handle horizontally
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
if(water[4*i][4*j+2]=='o'){
if(water[4*i][4*j+2-2]=='h')
{
water[4*i][4*j+2-2]='H';
water[4*i][4*j+2-1]='-';
}
else
{
water[4*i][4*j+2+2]='H';
water[4*i][4*j+2+1]='-';
}
}
}
}
//handle vertically
for(j=0;j<m;j++)
{
if(water[4*0][4*j+2]=='o')
{
water[4*0][4*j+2]='O';
water[4*0+1][4*j+2]='|';
water[4*0+2][4*j+2]='H';
}
}
for(j=0;j<m;j++)
{
if(water[4*(m-1)][4*j+2]=='o')
{
water[4*(m-1)][4*j+2]='O';
water[4*(m-1)-1][4*j+2]='|';
water[4*(m-1)-2][4*j+2]='H';
}
}
for(i=1;i<m-1;i++)
{
for(j=0;j<m;j++)
{
if(water[4*i][4*j+2]=='o'){
water[4*i][4*j+2]='O';
if(water[4*i-2][4*j+2]=='h')
{
water[4*i-2][4*j+2]='H';
water[4*i-1][4*j+2]='|';
}
else
{
water[4*i+2][4*j+2]='H';
water[4*i+1][4*j+2]='|';
}
}
}
}
//output
if(kase++) cout<<endl;
cout<<"Case "<<kase<<":"<<endl<<endl;
for(i=0;i<col+2;i++) cout<<"*";
cout<<endl;
for(i=0;i<row;i++)
{
cout<<"*";
for(j=0;j<col;j++) cout<<water[i][j];
cout<<"*"<<endl;
}
for(i=0;i<col+2;i++) cout<<"*";
cout<<endl;
}
return 0;
}