Problem L. Visual Cube

Problem L. Visual Cube

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(1T50) , denoting the number of test cases. In each test case, there are 3 integers a,b,c(1a,b,c20) , 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
..+-+
././|
+-+.+
|.|/.
+-+..
....+-+-+-+-+-+-+
.../././././././|
..+-+-+-+-+-+-+.+
./././././././|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/.
+-+-+-+-+-+-+.+..
|.|.|.|.|.|.|/...
+-+-+-+-+-+-+....
題目概述

給你一個立方體的長寬高,要你畫出一幅圖顯示該立方體
根據給出的測試樣例找到畫圖方法
輸入第一行爲一個整數T,代表有T組測試樣例
第二行有三個整數a,b,c 分別代表該立方體的長,寬,高

思路

根據樣例輸出我們可以發現他打出來的是一個立方體,我們將多餘的“.”去掉可以發現
這裏寫圖片描述

立方體的長是6,寬是2,高是4.所以
上底面的長是由6個“-”用“+”分隔開(或者6個“.”用“/”分隔開)。寬是由2個“/”,用“+”隔開
正面的長是由6個“-”用“+”分隔開(或者6個“.”用“|”分隔開)。寬是由4個“|”,用“+”隔開
側面的長是由2個“/”用“+”分隔開(或者2個“.”用“/”分隔開)。寬是由4個“|”,用“+”隔開

從體重可以看出打出來的圖是一個矩形那麼我們只需要將未填充的部分打上“.”即可
除此之外,我們還可以發現當輸入的長寬高是遞減時 會有不同

代碼
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int a,b,c,i,j,h;
        scanf("%d %d %d",&a,&b,&c);
        h=(c+b)*2+1;
        for(j=0;j<h;j++)
        {
            for(i=0;i<b*2-j;i++)//上底面部分填充"."
                printf(".");
            if(j%2==0)   //偶數行
            {
                printf("+");
                for(i=0;i<a;i++)
                    printf("-+");
                if(j>2*c&&j<2*b)    //上底面與側面交叉部分填充方法
                    for(i=0;i<c&&i<b;i++)
                        printf(".+");
                else
                    for(i=0;i<j/2&&i<((h-1-j)/2)&&i<b;i++)
                    printf(".+");  //
            }
            else    //奇數行
            {
                if(j<b*2)     //填充上底面
                {
                    printf("/");
                    for(i=0;i<a;i++)
                        printf("./");
                    printf("|");
                    if(j>2*c&&j<2*b)    //上底面與側面交叉部分填充方法
                    {
                        for(i=0;i<(j/2-(j-2*c)/2)-1;i++)
                            printf("/|");
                        printf("/");
                    }
                    else         
                    for(i=0;i<j/2;i++)
                        printf("/|");  //上底面與側面交叉部分填充結束
                }            //填充上底面結束
                else         //填充正面
                {
                     printf("|");
                     for(i=0;i<a;i++)
                        printf(".|");
                    if(j<2*c)           //正面與側面交叉部分填充方法
                        for(i=0;i<b;i++)
                        printf("/|");
                    else
                    {
                         for(i=0;i<((h-1-j)/2);i++)
                            printf("/|");
                        printf("/");
                    }                  //正面與側面交叉部分填充結束
                }            ////填充正面結束
            }
            for(i=0;i<j-c*2;i++)//側面部分填充"."
                printf(".");
            printf("\n");
        }
    }
}

這道題描述起來很抽象,希望各位大佬能夠多看看,好好體味一下。也可以按照自己的思路改寫一下代碼,通過與調試發現問題,加深理解吧。

留下你們的小心心吧@\/@

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章