分析:
这道题是一道很好的
耐心型的模拟题
我在代码中找到的是每一个小方块的最左下角,
坐标的计算要稍微注意一下
add(2*(n-i)+1+3*(k-1),4*(j-1)+1+2*(n-i));
这里写代码片
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m;
int mp[101][101],tot=0,mx=0,my=0;
char p[250][450];
void add(int x,int y)
{
mx=max(mx,x+5);
my=max(my,y+6);
p[x][y]='+'; p[x][y+1]='-';p[x][y+2]='-';p[x][y+3]='-';p[x][y+4]='+';
p[x+1][y]='|';p[x+1][y+1]=' ';p[x+1][y+2]=' ';p[x+1][y+3]=' ';p[x+1][y+4]='|';p[x+1][y+5]='/';
p[x+2][y]='|';p[x+2][y+1]=' ';p[x+2][y+2]=' ';p[x+2][y+3]=' ';p[x+2][y+4]='|';p[x+2][y+5]=' ';p[x+2][y+6]='+';
p[x+3][y]='+';p[x+3][y+1]='-';p[x+3][y+2]='-';p[x+3][y+3]='-';p[x+3][y+4]='+';p[x+3][y+5]=' ';p[x+3][y+6]='|';
p[x+4][y+1]='/';p[x+4][y+2]=' ';p[x+4][y+3]=' ';p[x+4][y+4]=' ';p[x+4][y+5]='/';p[x+4][y+6]='|';
p[x+5][y+2]='+';p[x+5][y+3]='-';p[x+5][y+4]='-';p[x+5][y+5]='-';p[x+5][y+6]='+';
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
scanf("%d",&mp[i][j]),tot+=mp[i][j];
memset(p,'.',sizeof(p));
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
for (int k=1;k<=mp[i][j];k++)
add(2*(n-i)+1+3*(k-1),4*(j-1)+1+2*(n-i));
for (int i=mx;i>=1;i--)
{
for (int j=1;j<=my;j++)
printf("%c",p[i][j]);
puts("");
}
return 0;
}