HDU 6330 Visual Cube(模拟)

题目链接:Visual Cube

题意

给定一个长方体的长宽高 a,b,c a , b , c ,按照样例输出长方体。

输入

第一行为一个整数 T (1T50) T   ( 1 ≤ T ≤ 50 ) ,接下去 T T 行每行三个整数 a,b,c (1a,b,c20)

输出

按样例输出。

样例

输入
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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值