题目链接:Visual Cube
题意
给定一个长方体的长宽高 a,b,c a , b , c ,按照样例输出长方体。
输入
第一行为一个整数 T (1≤T≤50) T ( 1 ≤ T ≤ 50 ) ,接下去 T T 行每行三个整数 。
输出
按样例输出。
样例
输入 |
---|
2 1 1 1 6 2 4 |
输出 |
![]() |
题解
由于前面覆盖后面,上面覆盖下面,右边覆盖左边,所以可以依次从后往前,从下往上,从左往右输出网格。
过题代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;
#define LL long long
const int maxn = 100 + 100;
int T, a, b, c, row, col;
char str[maxn][maxn];
void Draw(int x, int y, bool back) {
for(int i = 2 * c; i >= 0; i -= 2) {
for(int j = 0; j <= 2 * a; j += 2) {
str[x + i][y + j] = '+';
if(!back) {
str[x + i - 1][y + j] = '.';
str[x + i - 1][y + j + 1] = '/';
str[x + i][y + j + 1] = '.';
}
if(i != 2 * c) {
str[x + i + 1][y + j] = '|';
}
if(j != 0) {
str[x + i][y + j - 1] = '-';
}
if(i != 2 * c && j != 0) {
str[x + i + 1][y + j - 1] = '.';
}
}
}
}
int main() {
#ifdef LOCAL
freopen("test.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif // LOCAL
ios::sync_with_stdio(false);
scanf("%d", &T);
while(T--) {
scanf("%d%d%d", &a, &b, &c);
row = 2 * c + 1 + 2 * b;
col = 2 * a + 1 + 2 * b;
for(int i = 0; i < row; ++i) {
memset(str[i], '.', sizeof(char) * col);
str[i][col] = '\0';
}
for(int i = 0; i <= 2 * b; i += 2) {
int j = 2 * b - i;
bool back = false;
if(i == 0) {
back = true;
}
Draw(i, j, back);
}
for(int i = 0; i < row; ++i) {
printf("%s\n", str[i]);
}
}
return 0;
}