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
..+-+ ././| +-+.+ |.|/. +-+.. ....+-+-+-+-+-+-+ .../././././././| ..+-+-+-+-+-+-+.+ ./././././././|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/. +-+-+-+-+-+-+.+.. |.|.|.|.|.|.|/... +-+-+-+-+-+-+....
题意:不用多少都是理解的,就是打印立方体
题解:这题就是模拟,但是在模拟的时候容易出错。用一个二维数组保存,分为最上面,正面和侧面来模拟,这题需要耐心和要保持头脑清晰。具体代码如下:
#include<bits/stdc++.h>
using namespace std;
char cub[100][100];
int main(void){
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++)
cub[i][j]='.';
int d=2*b+1;
int f=2*b;
//上面
for(int i=1;i<=f;i++){
if(i%2){
for(int j=d;j<=d+2*a;j++){
if(j%2) cub[i][j]='+';
else cub[i][j]='-';
}
}
else{
for(int j=d;j<=d+2*a;j++){
if(j%2) cub[i][j]='.';
else cub[i][j]='/';
}
}
d--;
}
//正面
int l=2*b+2*c+1;
int m=2*a+1;
for(int i=f+1;i<=l;i++){ // f=2*b
if((i-f)%2){
for(int j=1;j<=m;j++){
if(j%2) cub[i][j]='+';
else cub[i][j]='-';
}
}
else{
for(int j=1;j<=m;j++){
if(j%2) cub[i][j]='|';
else cub[i][j]='.';
}
}
}
//侧面
int indexi=2*b+1;
for(int j=m; j<=m+b*2; j++)
{
if((j-a*2)%2)
{
for(int i=indexi; i<=indexi+c*2; i++)
{
if((i-indexi)%2==0)
cub[i][j]='+';
else cub[i][j]='|';
}
}
else
{
for(int i=indexi; i<=indexi+c*2; i++)
{
if((i-indexi)%2==0)
cub[i][j]='/';
else cub[i][j]='.';
}
}
indexi--;
}
int row=b*2+1+c*2,col= a*2+b*2+1;
for(int i=1; i<=row; i++)
{
for(int j=1; j<=col; j++)
printf("%c",cub[i][j]);
puts("");
}
}
return 0;
}