L - Problem L. Visual Cube (模拟打印图)

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 aa, width bb and height cc, please write a program to display the cube. 

Input

The first line of the input contains an integer T(1≤T≤50)T(1≤T≤50), denoting the number of test cases. 
In each test case, there are 33 integers a,b,c(1≤a,b,c≤20)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

..+-+
././|
+-+.+
|.|/.
+-+..
....+-+-+-+-+-+-+
.../././././././|
..+-+-+-+-+-+-+.+
./././././././|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/.
+-+-+-+-+-+-+.+..
|.|.|.|.|.|.|/...
+-+-+-+-+-+-+....

【解析】

题意:给你长a宽b高c,打印出这个长方体。

模拟完了真的心累。

#include <bits/stdc++.h>
using namespace std;
int main()
{
	char cub[100][100];
	int a, b, c, t;
	scanf("%d", &t);
	while (t--)
	{
		memset(cub, '.', sizeof(cub));
		scanf("%d%d%d", &a, &b, &c);
		for (int j = 2*b+2*c+1; j >= 2 * b + 1; j -= 2) //正面
			for (int i = 1; i <= 2 * a + 1; i++) 
			{
				if (i & 1) cub[j][i] = '+';
				else cub[j][i] = '-';
			}
		for (int j = 2 * b + 2 * c; j>2 * b + 1; j -= 2)//正面
			for (int i = 1; i <= 2 * a + 1; i += 2) 
				cub[j][i] = '|';

		int beg = 2;
		for (int i = 2 * b; i >= 1; i--)//上面
		{
			for (int j = beg; j < 2 * a + 1 + beg; j ++)
			{
				if (i & 1)
				{
					if (j & 1) cub[i][j] = '+';
					else cub[i][j] = '-';
				}
				else 
					if (j % 2 == 0) cub[i][j] = '/';
			}
			beg++;
		}

		beg = 2 * b + 2 * c;
		for (int j = 2 * a + 2; j <= 2*a+2*b+1; j++)//侧面
		{
			for (int i = beg; i > beg - 2 * c; i--) 
			{
				if (j &1 )
				{
					if (i & 1) cub[i][j] = '+';
					else cub[i][j] = '|';
				}
				else
					if (i % 2 == 0) cub[i][j] = '/';
			}
			beg--;
		}
		for (int i = 1; i <= 2 * b + 2 * c + 1; i++)
		{
			for (int j = 1; j <= 2*a+2*b+1; j++) 
				printf("%c", cub[i][j]);
			printf("\n");
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/waterboy_cj/article/details/81392639