You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 2000; // 竞赛的内存空间一般不做严格限制,所以,能开大一点就开大一点
int m, n; // m行n列
char a[N][N]; // 结果数组,一个立方体是7列上下是6行,约7*50
char b[10][10] = {
" +---+", // b[0][2],5个字符
" / /|", // b[1][1],6个字符
"+---+ |", // b[2][0],7个字符
"| | +", // b[3][0],7个字符
"| |/ ", // b[4][0],6个字符
"+---+ " // b[5][0],5个字符
};
int height, minx = 1000, maxy = 1000;
// 试错的思路
void draw(int i, int j) {
memcpy(&a[i - 0][j], &b[5][0], 5);
memcpy(&a[i - 1][j], &b[4][0], 6);
memcpy(&a[i - 2][j], &b[3][0], 7);
memcpy(&a[i - 3][j], &b[2][0], 7);
memcpy(&a[i - 4][j + 1], &b[1][1], 6);
memcpy(&a[i - 5][j + 2], &b[0][2], 5);
minx = min(minx, i - 5);
maxy = max(maxy, j + 6);
}
int main() {
cin >> m >> n;
int x = 1000, y = 1000; // 三维坐标系原点坐标
// ① 绘制顺序x,y,z:从后到前,从左到右,从下到上
for (int i = 0; i < m; i++) { // ① X由小到大从后到前
x += 2, y -= 2; // 不断的调整起始位置
for (int j = 0; j < n; j++) { // ② Y由小到大从左到右
cin >> height;
for (int k = 0; k < height; k++) // ③ 从下往上
draw(x - 3 * k, y + 4 * j);
}
}
// 输出
for (int i = minx; i <= x; i++) {
for (int j = y; j <= maxy; j++) {
if (a[i][j] == 0)
cout << '.';
else
cout << a[i][j];
}
cout << endl;
}
return 0;
}