HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube

本文介绍了一道关于3D立方体可视化的编程题,通过分析题目要求,利用C++实现了一个绘制不同视角下立方体的程序。该程序能够根据输入的尺寸参数,输出由特定符号组成的立方体正视图、俯视图和右视图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem L. Visual Cube

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1473    Accepted Submission(s): 694

 

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

解题思路:立体图分为:俯视图 + 正视图 + 右视图,此题先刷 俯视图 + 正视图,最后刷 右视图;一开始先记录每个视图有哪些规律图案,比如:“+-+-+-+”、“/././././”,然后再创建一个全是“点”的二维数组,把它描上去即可。

AC 代码

#include<bits/stdc++.h>
#include<cmath>

#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;

int main()
{
    int T; scanf("%d",&T);
    int a,b,c;
    while(T-- && ~scanf("%d%d%d",&a,&b,&c))
    {
        string zf,xd,sd,dx,sz;
        for(int i=0;i<a;i++)
        {
            zf.append("+-");
            xd.append("/.");
            sd.append("|.");
        }
        zf.append("+"); xd.append("/"); sd.append("|");

        for(int i=0;i<c;i++)
        {
            sz.append("|+");
            dx.append("./");
        }

//        cout<<"+-:"<<zf<<endl;
//        cout<<"/.:"<<xd<<endl;
//        cout<<"|.:"<<sd<<endl;
//        cout<<"./:"<<dx<<endl;
//        cout<<"|+:"<<sz<<endl;

        int rlen=2*c+1+2*b,clen=2*a+1+2*b;
        int con=2*b;
        char g[rlen+5][clen+5]; mem(g,'.');
        for(int i=0;i<rlen;i++,con--)
        {
            for(int j=0;j<clen;j++)
            {
                if(con>0)
                {
                    if(j+con<clen && i%2==0 && j<zf.length())
                        g[i][j+con]=zf[j];
                    else if(j+con<clen && i%2==1 && j<xd.length())
                        g[i][j+con]=xd[j];
                }
                else
                {
                    if(i%2==0 && j<zf.length())
                        g[i][j]=zf[j];
                    else if(i%2==1 && j<sd.length())
                        g[i][j]=sd[j];
                }
            }
        }


        // 正视图和俯视图刷完,可以快速排错
//        for(int i=0;i<rlen;i++)
//        {
//            for(int j=0;j<clen;j++)
//            {
//                printf("%c",g[i][j]);
//            }
//            puts("");
//        }
//        puts("-----------------");


        // 右视图刷完
        con=2*b;
        int h=2*c,t=0;
        for(int j=clen-1;j>=0 && con--;j--,t++)
        {
            for(int i=1+t;i<=h+t;i++)
            {
                if(j%2==0 && i-1-t<sz.length())
                    g[i][j]=sz[i-1-t];
                else if(j%2==1 && i-1-t<dx.length())
                    g[i][j]=dx[i-1-t];
            }
        }

        for(int i=0;i<rlen;i++)
        {
            for(int j=0;j<clen;j++)
            {
                printf("%c",g[i][j]);
            }
            puts("");
        }
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

陆克和他的代码

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

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

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

打赏作者

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

抵扣说明:

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

余额充值