Problem L. Visual Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1131 Accepted Submission(s): 702
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
..+-+
././|
+-+.+
|.|/.
+-+..
....+-+-+-+-+-+-+
.../././././././|
..+-+-+-+-+-+-+.+
./././././././|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/|
+-+-+-+-+-+-+.+.+
|.|.|.|.|.|.|/|/.
+-+-+-+-+-+-+.+..
|.|.|.|.|.|.|/...
+-+-+-+-+-+-+....
Source
2018 Multi-University Training Contest 3
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
string s[100];
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
for(int i = 0; i < 2*b+1; i++)
{
for(int j = 0; j < 2*b-i; j++)
s[i] += ".";
if(i%2 == 0)
{
for(int j = 0; j < a; j++)
s[i] += "+-";
s[i] += "+";
}
if(i%2 == 1)
{
for(int j = 0; j < a; j++)
s[i] += "/.";
s[i] += "/";
}
}
int len = 2*b+1;
for(int i = 0; i < 2*c; i++)
{
if(i % 2 == 0)
{
for(int j = 0; j < a; j++)
s[i+len] += "|.";
s[i+len] += "|";
}
else
{
for(int j = 0; j < a; j++)
s[i+len] += "+-";
s[i+len] += "+";
}
}
for(int i = 2*b; i > 0; i--)
for(int j = 0; j < 2*c; j++)
{
if(i%2 == 0)
{
if(j % 2 == 0)
s[i+j] += '.';
else s[i+j] += '/';
}
else {
if(j % 2 == 0)
s[i+j] += '|';
else s[i+j] += '+';
}
}
for(int i = 0; i < 2*b; i++)
{
for(int j = 0; j < 2*b-i; j++)
s[2*b+2*c-i] += '.';
}
for(int i = 0; i < 2*b+2*c+1; i++)
cout << s[i] << endl;
}
return 0;
}