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;
}
原文地址:https://www.cnblogs.com/longl/p/9392308.html