HDU-6330 Problem L. Visual Cube(模拟)

Problem L. Visual Cube

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 145    Accepted Submission(s): 108


 

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.

 

 

Source

2018 Multi-University Training Contest 3

#include<bits/stdc++.h>
using namespace std;
//#define clr(a) memset(a,0,sizeof(a));
const int N =110;
int t,n,m,a,b,c;
char s[N][N];
int main(){
    scanf("%d",&t);
    while(t--){
        memset(s,0,sizeof(s));
        scanf("%d%d%d",&a,&b,&c);
        m = 2*a+2*b+1;
        n = 2*c+2*b+1;
        int temp = 2*b;

        for(int i=1;i<=2*b;i++,temp--){
            for(int j=1;j<=temp;j++){
                s[i][j] = '.';
               // cout<<i<<"   "<<j<<endl;
            }
        }
        temp = 2*b;
        for(int i=1;i<=2*b;i+=2){
            for(int j=temp+1;j<=m-i+1;j++){
                if(s[i][j-1]=='+')  s[i][j] = '-';
                else s[i][j] = '+';
            }
            temp-=2;
        }
        temp = 2*b;
        for(int i=2;i<=2*b;i+=2){
            for(int j=temp;j<=m-i+1;j++){
                if(s[i][j-1]=='/')  s[i][j] = '.';
                else s[i][j] = '/';
            }
            temp-=2;
        }
        for(int i=2*b+1;i<=n;i+=2){
            for(int j=1;j<=2*a+1;j++){
                if(s[i][j-1]=='+')  s[i][j] = '-';
                else s[i][j] = '+';
            }
        }
        for(int i=2*b+2;i<=n;i+=2){
            for(int j=1;j<=2*a+1;j++){
                if(s[i][j-1] == '|')  s[i][j] = '.';
                else s[i][j] = '|';
            }
        }
        temp = 2*b;
        for(int i=n;i>n-2*b;i--,temp--){
            for(int j=m-temp+1;j<=m;j++){
                s[i][j] = '.';
            }
        }
        for(int i=m;i>m-2*b;i-=2){
            for(int j=2;j<=n;j+=2){
                if(!s[j][i])    s[j][i] = '|';
            }
        }
        for(int i=m;i>m-2*b;i-=2){
            for(int j=1;j<=n;j+=2){
                if(!s[j][i])    s[j][i] = '+';
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(!s[i][j]&&s[i][j-1]=='+'&&s[i][j+1]=='+'){
                    s[i][j] = '.';
                }
                if(!s[i][j]&&s[i][j-1]=='|'&&s[i][j+1]=='|'){
                    s[i][j] = '/';
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(!s[i][j])    s[i][j] = '/';
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                printf("%c",s[i][j]);
            }
            cout<<endl;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/l18339702017/article/details/81293184