题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6330

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:

 

题意:输入T组测试样例,每组测试样例输入立方体的长宽高,然后打印出次立方体(例如样例输出)。

思路:这道题其实不难,就是一行一行的模拟,但要注意的是模拟的时候是通过模拟上面、前面、侧面的方法模拟的,而不是根据前面几行、后面几行和中间几行的方法模拟的,这样是错的,因为如果高很小,而宽很大时(即宽远大于高时)你就会发现这种方法的中间几行变成负的了,所以这种方法不可行,我一开始就是这样做的,还死活找不到错哪,可怜我快wa哭了(唉,弱鸡)

My  DaiMa:

//#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//int n,a[55][55];
int main()
{
    int t,a,b,c;
    char s[100][100];
    cin >> t;
    while( t-- )
    {
        cin >> a >> b >> c;
        for( int i = 0; i < 100; i++)
        {
            for( int j = 0; j < 100; j++)
                s[i][j] = '.';
        }
        for(int i = 0; i < 2*b; i++)//上面
        {
            for( int j = 2*b-i ; j < 2*a+2*b-i; j++)
            {
                if(i%2 == 0)
                {
                    if(j%2 == 0)
                        s[i][j] = '+';
                    else
                        s[i][j] = '-';
                }
                else
                {
                    if(j%2 != 0)
                        s[i][j] = '/';
                }
            }
        }
        for( int i = 2*b; i < 2*c+1+2*b; i++)//前面
        {
            for( int j = 0; j < 2*a+1; j++)
            {
                if(i%2 == 0)
                {
                    if(j%2 == 0)
                        s[i][j] = '+';
                    else
                        s[i][j] = '-';
                }
                else
                {
                    if(j%2 == 0)
                        s[i][j] = '|';
                }
            }
        }
        for(int j = 2*a+1; j < 2*b+2*a+1; j++)//侧面
        {
            for( int i = 2*a+2*b-j; i < 2*a+2*b+1-j+2*c; i++)
            {
                if(j%2 == 0)
                {
                    if(i%2 == 0)
                        s[i][j] = '+';
                    else
                        s[i][j] = '|';
                }
                else
                {
                    if(i%2 != 0)
                        s[i][j] = '/';
                }
            }
        }
        for(int i = 0; i < 2*c+1+2*b; i++)
        {
            for(int j = 0; j < 2*a+1+2*b; j++)
                printf("%c",s[i][j]);
            printf("\n");
        }
    }
}