Problem L Visual Cube

Posted longl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Problem L Visual Cube相关的知识,希望对你有一定的参考价值。

Problem L Visual Cube

题目:

 

Problem L. Visual Cube

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

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


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
 
 技术分享图片

 

 

Source
 

 

Recommend
chendu

 

思路:

    模拟题,先用‘’.‘’填充所有的,然后先填顶面,再填正面,最后填侧面。题目不难,但是有些复杂,所以要细心,注意分类讨论,注意边界的情况。

 

代码:

#include<cstdio>
using namespace std;
char s[100][100];
int maxn = 100;
void put(int row,int col)
{
    for(int i=1; i<=row; i++)
    {
        for(int j=1; j<=col; j++)
            printf("%c",s[i][j]);
        puts("");
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);

        for(int i=1; i<100; i++)
            for(int j=1; j<100; j++)
                s[i][j]=.;
        ///顶面
        int indexj = b*2+1;
        for(int i=1; i<=b*2; i++)
        {
            if(i%2)
            {
                for(int j=indexj; j<=indexj+2*a; j++)
                {
                    if(j%2)s[i][j]=+;
                    else s[i][j]=-;
                }
            }
            else
            {
                for(int j=indexj; j<=indexj+2*a; j++)
                {
                    if(j%2==0)s[i][j]=/;
                    else s[i][j]=.;
                }
            }
            indexj--;

        }
        ///正面
        for(int i=b*2+1; i<=b*2+1+c*2; i++)
        {
            if((i-b*2)%2)
            {
                for(int j=1; j<=a*2+1; j++)
                {
                    if(j%2)s[i][j]=+;
                    else s[i][j]=-;
                }
            }
            else
            {
                for(int j=1; j<=a*2+1; j++)
                {
                    if(j%2)s[i][j]=|;
                    else s[i][j]=.;
                }
            }
        }
        ///侧面
        int indexi=2*b+1;
        for(int j=a*2+1; j<=a*2+b*2+1; j++)
        {

            if((j-a*2)%2)
            {
                for(int i=indexi; i<=indexi+c*2; i++)
                {
                    if((i-indexi)%2==0)
                        s[i][j]=+;
                    else s[i][j]=|;
                }
            }
            else
            {
                for(int i=indexi; i<=indexi+c*2; i++)
                {
                    if((i-indexi)%2==0)
                        s[i][j]=/;
                    else s[i][j]=.;
                }

            }
            indexi--;


        }

        int hh = b*2+1+c*2;
        int ll = a*2+b*2+1;
        put(hh,ll);
    }


    return 0;
}

 










以上是关于Problem L Visual Cube的主要内容,如果未能解决你的问题,请参考以下文章

Visual Studio 2012-2019的130多个jQuery代码片段。

text Visual Basic代码片段

HDU 6330--Visual Cube(构造,计算)

如何在 Resharper IntelliSense 中显示所有 Visual Studio 代码片段?

在 Visual Studio 中创建构造函数的代码片段或快捷方式

Visual Studio 自定义代码片段在方法定义的参数列表中不起作用