2018暑期HDU多校第三场—— L Visual Cube
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
..+-+ ././| +-+.+ |.|/. +-+.. ....+-+-+-+-+-+-+ .../././././././| ..+-+-+-+-+-+-+.+ ./././././././|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/. +-+-+-+-+-+-+.+.. |.|.|.|.|.|.|/... +-+-+-+-+-+-+....
题解:
就是简单的模拟输出图像,不过如果是一行一行输出的要注意长宽较大高较小的情况,建议把图像拆成一个矩形和两个菱形来输出,这样可以回避很多麻烦。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char board[105][105];
int main(){
int T;
int A,B,C;
scanf("%d",&T);
while(T--){
memset(board,'.',sizeof board);
scanf("%d %d %d",&A,&B,&C);
int L = 2*C+1+2*B;
int LL = 2*A+2*B+1;
for(int i=1 ; i<=L ; ++i){//填侧面的菱形
int l1 = 0,l2 = 0;
if(i<=B*2){
l1 = 2*B-i+1+1+2*A;
}
if(L-i<B*2){
l2 = 2*B-(L-i);
}
for(int j=l1+1 ; j<=LL-l2 ; ++j){
if(i&1){
if(j&1)board[i][j] = '+';
else board[i][j] = '.';
}
else {
if(j&1)board[i][j] = '|';
else board[i][j] = '/';
}
}
}
for(int i=1 ; i<=B*2 ; ++i){//填上边的菱形
int t = 2*B-i+1+1;
for(int j=t ; j<=t+2*A-1 ; j+=2){
if(i&1){
board[i][j] = '+';
board[i][j+1] = '-';
}
else{
board[i][j] = '/';
board[i][j+1] = '.';
}
}
if(i&1)board[i][t+2*A] = '+';
else board[i][t+2*A] = '/';
}
for(int i=L ; i>2*B ; i--){//填左下角的大矩形
if(i&1){
for(int j=1 ; j<=2*A ; j+=2){
board[i][j] = '+';
board[i][j+1] = '-';
}
board[i][2*A+1] = '+';
}
else {
for(int j=1 ; j<=2*A ; j+=2){
board[i][j] = '|';
board[i][j+1] = '.';
}
board[i][2*A+1] = '|';
}
}
for(int i=1 ; i<=L ; ++i){//输出
for(int j=1 ; j<=LL ; ++j){
printf("%c",board[i][j]);
}
printf("\n");
}
}
return 0;
}