zoukankan      html  css  js  c++  java
  • 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("
    ");
            }
        }
        
        return 0;
    }
  • 相关阅读:
    如何利用迅雷下载百度云?
    Windows 8.1/Server 2012 R2/Embedded 8.1 with Update 3(MSDN最新版)
    Visual Studio 2013 and .NET 4.6
    明朝那些事儿的作者的经历
    嵌入式OS的现状、智能的物联网与未来的机器人
    系统战略+极致运营=战无不胜的千机团
    惠普笔记本按开机键后电源灯亮的,但是屏幕一直是黑的,只有大写锁定键闪烁,闪3次一个循环,听得到风扇
    Android平台免Root无侵入AOP框架Dexposed使用详解
    iOS-OC-APP热更新,动态更新(仿QQ打开或关闭某个功能)
    ios app 实现热更新(无需发新版本实现app添加新功能)
  • 原文地址:https://www.cnblogs.com/vocaloid01/p/9514022.html
Copyright © 2011-2022 走看看