HDU6330 Visual Cube

3D立方体图形绘制
本文介绍了一种使用C++编程语言绘制3D长方体图形的方法,通过具体实例展示了如何根据给定的长宽高参数,生成相应的立体图形表示。代码详细解释了绘制过程,包括顶部、前部和侧面的构造。

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 aa, width bb and height cc, please write a program to display the cube. 

Input

The first line of the input contains an integer T(1≤T≤50)T(1≤T≤50), denoting the number of test cases. 
In each test case, there are 33 integers a,b,c(1≤a,b,c≤20)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;
#define mem(a,b)memset(a,b,sizeof(a))
char p[200][200];
void draw(int x,int y)
{
    for(int i=1; i<=x; i++)
    {
        for(int j=1; j<=y; j++)
            printf("%c",p[i][j]);
        printf("\n");
    }
}
int main()
{
    int t,a,b,c;
    scanf("%d",&t);
    while(t--)
    {
        mem(p,'.');
        scanf("%d%d%d",&a,&b,&c);
        for(int i=1; i<=2*b; i++) //上面
            if(i&1)
            {
                for(int j=2*b+1-i+1,k=1; j<=2*a+2*b+1&k<=a+1; j+=2,k++)
                    p[i][j]='+';
                for(int j=2*b+1-i+2,k=1; j<=2*a+2*b+1&&k<=a; j+=2,k++)
                    p[i][j]='-';
            }
            else
                for(int j=2*b+1-i+1,k=1; j<=2*a+2*b+1&&k<=a+1; j+=2,k++)
                    p[i][j]='/';
        for(int i=2*b+1; i<=2*c+2*b+1; i++) //正面
            if(i&1)
            {
                for(int j=1,k=1; k<=a+1; j+=2,k++)
                    p[i][j]='+';
                for(int j=2,k=1; k<=a; j+=2,k++)
                    p[i][j]='-';
            }
            else
                for(int j=1,k=1; k<=a+1; j+=2,k++)
                    p[i][j]='|';
        for(int i=2*a+2*b+1,k=1; k<=2*b; i--,k++) //侧面
            if(k&1)
                for(int j=k,pos=1; j<=k+2*c; j++,pos++)
                    if(pos&1)
                        p[j][i]='+';
                    else
                        p[j][i]='|';
            else
                for(int j=k,pos=1; j<=k+2*c+1; j++,pos++)
                    if(pos&1)
                        p[j][i]='/';
        draw(2*c+2*b+1,2*a+2*b+1);// x=2*c+2*b+1 y=2*a+2*b+1 
    }
    return 0;
}

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鱼爱吃火锅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值