hdu 6330 Problem L. Visual Cube(模拟)

Little Q likes solving math problems very much. Unluckily, however, he does not have good spatial ability. Everytime he meets a 3D geometry problem, he will struggle to draw a picture.
Now he meets a 3D geometry problem again. This time, he doesn’t want to struggle any more. As a result, he turns to you for help.
Given a cube with length a, width b and height c
, please write a program to display the cube.

Input
The first line of the input contains an integer T(1≤T≤50), denoting the number of test cases.
In each test case, there are 3 integers a,b,c(1≤a,b,c≤20)
, denoting the size of the cube.

Output
For each test case, print several lines to display the cube. See the sample output for details.
Sample Input

2
1 1 1
6 2 4

Sample Output

..+-+
././|
+-+.+
|.|/.
+-+..
....+-+-+-+-+-+-+
.../././././././|
..+-+-+-+-+-+-+.+
./././././././|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/.
+-+-+-+-+-+-+.+..
|.|.|.|.|.|.|/...
+-+-+-+-+-+-+....
#include<bits/stdc++.h>
using namespace std;

int main(){
    int t, a, b, c, n, m, i, j;
    scanf("%d", &t);
    char mp[150][150];
    while(t--){
        scanf("%d%d%d", &a, &b, &c);
        n = b * 2 + c * 2 + 1; //行 = 高*2+宽*2+1
        m = b * 2 + a * 2 + 1; //列 = 长*2+宽*2+1
        for(i = 0; i < n; i++)//将所有点初始化为'.'
            for(j = 0; j < m; j++)
                mp[i][j] = '.';
        for(i = 2*b; i < n; i++){
            for(j = 0; j <= 2*a; j++){//先输出左下角的矩形
                if(i%2 == 0 && j%2 == 0)    mp[i][j] = '+';
                if(i%2 == 0 && j%2)         mp[i][j] = '-';
                if(i%2 && j%2 == 0)         mp[i][j] = '|';
            }
        }
        for(i = 0; i <= 2*a; i++){//利用左下角矩形的宽来斜向右上方做平行四边形
            for(j = 1; j <= b; j++){
                if(mp[2*b][i] == '+'){
                    mp[2*b - 2*j + 1][i + 2*j - 1] = '/';
                    mp[2*b - 2*j][i + 2*j] = '+';
                }
                else{
                    mp[2*b - 2*j][i + 2*j] = '-';
                }
            }
        }
        for(i = n-1; i >= 2*b; i--){//利用左下角矩形的长斜向右上方做平行四边形
            for(j = 1; j <= b; j++){
               if(mp[i][2*a] == '+'){
                    mp[i - 2*j + 1][2*a + 2*j - 1] = '/';
                    mp[i - 2*j][2*a + 2*j] = '+';
               }
               else{
                    mp[i - 2*j][2*a + 2*j] = '|';
               }
            }
        }
        for(i = 0; i < n; i++){
            for(j = 0; j < m; j++){
                printf("%c", mp[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ling_wang/article/details/81462078