四、立体图
Pku原题,编号2330
算不上难题,但是比较麻烦,细心点就ok了。
先计算好画布的大小,再写一个根据左下角坐标绘制一个单位立方体的子程序。
然后遵循下面法则,不停绘制若干个立方体。(此处能体现出分割程序的伟大)
因为要不停的覆盖,所以要遵循“视觉法则”:
1. 先绘里层再绘外层
2. 先绘底层再绘上层
3. 先回左边再绘右边
参考程序:
program drawing;
const
inp='drawing.in';
oup='drawing.out';
var
m,n,i,j,k,x,y,h,tmp,maxx,maxy:longint;
map:array[1..1000,1..1000] of char;//画布
a:array[1..50,1..50] of integer;//记录输入的矩阵
procedure flink;
begin
assign(input,inp);
reset(input);
assign(output,oup);
rewrite(output);
end;
procedure fclose;
begin
close(input);
close(output);
end;
procedure print;//输出画布
var
i,j:longint;
begin
for i:= 1 to maxx do
begin
for j:= 1 to maxy do
write(map[i,j]);
if i<>maxx then writeln;
end;
end;
procedure draw(x,y:longint);//在画布(map数组)上绘制左下角坐标为(x,y)的一个单位立方体
begin
map[x,y]:='+';map[x,y+1]:='-'; map[x,y+2]:='-';map[x,y+3]:='-';map[x,y+4]:='+';
dec(x);
map[x,y]:='|';map[x,y+1]:=' '; map[x,y+2]:=' ';map[x,y+3]:=' ';map[x,y+4]:='|';
map[x,y+5]:='/';
dec(x);
map[x,y]:='|';map[x,y+1]:=' '; map[x,y+2]:=' ';map[x,y+3]:=' ';map[x,y+4]:='|';
map[x,y+5]:=' ';map[x,y+6]:='+';
dec(x);
map[x,y]:='+';map[x,y+1]:='-'; map[x,y+2]:='-';map[x,y+3]:='-';map[x,y+4]:='+';
map[x,y+5]:=' ';map[x,y+6]:='|';
dec(x); inc(y);
map[x,y]:='/';map[x,y+1]:=' '; map[x,y+2]:=' ';map[x,y+3]:=' ';map[x,y+4]:='/';
map[x,y+5]:='|';
dec(x);inc(y);
map[x,y]:='+';map[x,y+1]:='-'; map[x,y+2]:='-';map[x,y+3]:='-';map[x,y+4]:='+';
end;
begin
flink;
for i:= 1 to 1000 do
for j:= 1 to 1000 do
map[i,j]:='.'; //初始化画布
readln(m,n);
//计算画布大小maxx * maxy
maxy:=n*4+1+m*2;
maxx:=0;
for i:= 1 to m do
begin
tmp:=0;
for j:= 1 to n do
begin
read(a[i,j]);
if a[i,j]>tmp then tmp:=a[i,j];
end;
tmp:=tmp*3+3+(m-i)*2;
if tmp >maxx then maxx:=tmp;
readln;
end;
//开始往画布上绘图
for i:= 1 to m do
for j:= 1 to n do
begin
x:=maxx-(m-i)*2;//第i层第j列最下方立方体左下角点的位置(x,y)
y:=(m-i)*2+(j-1)*4+1;
for k:= 1 to a[i,j] do
draw(x-(k-1)*3,y);//绘制每层的若干个一个单位立方体
end;
print;//输出画布
fclose;
end.
我是死做
从最后一排画,然后向上,然后重复前面的往前面推