Visual Cube(水题)

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.

这道题自己太菜,水题都写了好久。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    int a,b,c;
    while(t--)
    {
        scanf("%d%d%d",&a,&b,&c);
        int point1=2*b;
        int point2=0;
        int chang=2*(a+b)+1;
     
        int hh=2*b;
        int logal=0;
        for(int i=1;i<=hh;i++)
        {
            for(int j=1;j<=point1;j++)
            {
                cout<<'.';
            }
            for(int j=1+point1;j<=2*a +1+point1;j++)
            {
                if(i%2==0)
                {
                    if(j%2==0)
                    {
                        cout<<'/';
                    }
                    else
                        cout<<'.';
                }
                else
                {
                    if(j%2==0)
                        cout<<'-';
                    else
                        cout<<'+';
                }
            }
            if(i>2*c+1)
                logal=1;
            if(i<=2*c+1)
            {
                for(int j=2*a +1+point1+1;j<=chang;j++)
                {
                    if(i%2==1)
                    {
                        if(j%2==1)
                        {
                            cout<<'+';
                        }
                        else
                            cout<<'.';
                    }
                    else
                    {
                        if(j%2==1)
                            cout<<'|';
                        else
                            cout<<'/';
                    }
                }
            }
            else
            {
                ++point2;
                ///cout<<point2<<"&&&&&&&&&&&&&&&"<<endl;
                    for(int j=2*a +1+point1+1 ;j<=chang-point2;j++)
                    {
                        if(i%2==1)
                        {
                            if(j%2==1)
                            {
                                cout<<'+';
                            }
                            else
                                cout<<'.';
                        }
                        else
                        {
                            if(j%2==1)
                                cout<<'|';
                            else
                                cout<<'/';
                        }
                    }
                    for(int j=chang-point2+1;j<=chang;j++)
                    {
                        cout<<'.';
                    }
            }
            point1--;
            cout<<endl;
        }
        for(int i=2*b+1;i<=2*b+2*c+1;i++)
        {
            for(int j=1;j<=2*a+1;j++)
            {
                if(i%2==1)
                {
                    if(j%2==0)
                        cout<<'-';
                    else
                        cout<<'+';
                }
                else
                {
                    if(j%2==0)
                        cout<<'.';
                    else
                        cout<<'|';
                }
            }
            if(logal==0)
            {
                if(i>2*c+1)
                {
                    ++point2;
                    for(int j=2*a+2;j<=chang-point2;j++)
                    {
                        if(i%2==0)
                        {
                            if(j%2==0)
                                cout<<'/';
                            else
                                cout<<'|';
                        }
                        else
                        {
                            if(j%2==0)
                                cout<<'.';
                            else
                                cout<<'+';
                        }
                    }
                    for(int j=chang-point2+1;j<=chang;j++)
                    {
                        cout<<'.';
                    }
                }
                else
                {
                    for(int j=2*a+2;j<=chang;j++)
                    {
                        if(i%2==0)
                        {
                            if(j%2==0)
                                cout<<'/';
                            else
                                cout<<'|';
                        }
                        else
                        {
                            if(j%2==0)
                                cout<<'.';
                            else
                                cout<<'+';
                        }
                    }
                }
            }
            if(logal==1)
            {
                ++point2;
                for(int j=2*a+2;j<=chang-point2;j++)
                {
                     if(i%2==0)
                    {
                        if(j%2==0)
                            cout<<'/';
                        else
                            cout<<'|';
                    }
                    else{
                        if(j%2==0)
                            cout<<'.';
                        else
                            cout<<'+';
                    }
                }
                for(int j=chang-point2+1;j<=chang;j++)
                {
                    cout<<'.';
                }
            }
            cout<<endl;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/xianpingping/article/details/81284898