2018 Multi-University Training Contest 3 Problem L. Visual Cube

原题:http://acm.hdu.edu.cn/showproblem.php?pid=6330

Problem Description

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

..+-+
././|
+-+.+
|.|/.
+-+..
....+-+-+-+-+-+-+
.../././././././|
..+-+-+-+-+-+-+.+
./././././././|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/.
+-+-+-+-+-+-+.+..
|.|.|.|.|.|.|/...
+-+-+-+-+-+-+....

分析:模拟题,题目意思是输入a, b, c代表一个长方体的长宽高,要求画出这个长方体的3D图。做法很容易,只不过要注意细节,做的时候因为一个等号的原因,挖了两发。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 500;
char pic[maxn][maxn];
int t, n, m;
int a, b, c;
int x, y;


int main(){
    scanf("%d", &t);
    while(t--){
        memset(pic, '.', sizeof(pic));
        scanf("%d%d%d", &a, &b, &c);
        x = 2*(c+b) + 1;
        y = 2*(a+b) + 1;
        for(int j=x; j>=2*b+1; j-=2){
            for(int i=1; i<=2*a+1; i++){
                if(i&1) pic[j][i] = '+';
                else pic[j][i] = '-';        
            }
        }
        for(int j=x-1; j>2*b+1; j-=2){
            for(int i=1; i<=2*a+1; i+=2){
                if(i&1) pic[j][i] = '|';        
            }
        }
        int pos = 2;
        for(int i=2*b; i>=1; i--){
            for(int j=pos; j<2*a+1+pos; j++){
                if(i&1){
                    if(j&1) pic[i][j] = '+';
                    else pic[i][j] = '-';
                }
                else{
                    if(j%2 == 0) pic[i][j] = '/';
                }
            }
            pos++;
        }
        pos = x-1;
        for(int j=2*a+2; j<=y; j++){
            for(int i=pos; i>pos-2*c; i--){
                if(j%2 == 0){
                    if(i%2 == 0) pic[i][j] = '/';
                }
                else {
                    if(i&1) pic[i][j] = '+';
                    else pic[i][j] = '|';
                }
            }    
            pos--;
        }
        for(int i=1; i<=x; i++){
            for(int j=1; j<=y; j++){
                printf("%c", pic[i][j]);
            }
            printf("\n");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/m0_37611893/article/details/81292117