HDU 6330 Visual Cube(模拟)

本文介绍了一道关于输出三维立方体图形的编程题。题目要求根据给定的长宽高,通过编程模拟生成并展示相应的3D立方体图形。文章提供了一段使用C++实现的代码示例,详细展示了如何通过坐标计算和字符填充来构造立方体的各个面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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<cstdio>
const int N=200;
int T,a,b,c,n,m,i,j;char f[N][N];
int main(){
  scanf("%d",&T);
  while(T--){
    scanf("%d%d%d",&a,&b,&c);
    n=b*2+c*2+1;
    m=a*2+b*2+1;
    for(i=1;i<=n;i++)for(j=1;j<=m;j++)f[i][j]='.';
    for(i=1;i<=b;i++)for(j=1;j<=a;j++){
      f[i*2-1][j*2+1+b*2-i*2]='+';
      f[i*2-1][j*2+2+b*2-i*2]='-';
      f[i*2-1][j*2+3+b*2-i*2]='+';
      f[i*2][j*2+b*2-i*2]='/';
      f[i*2][j*2+2+b*2-i*2]='/';
    }
    for(i=1;i<=c;i++)for(j=1;j<=a;j++){
      f[i*2+b*2-1][j*2-1]='+';
      f[i*2+b*2-1][j*2]='-';
      f[i*2+b*2-1][j*2+1]='+';
      f[i*2+b*2][j*2-1]='|';
      f[i*2+b*2][j*2+1]='|';
      f[i*2+b*2+1][j*2-1]='+';
      f[i*2+b*2+1][j*2]='-';
      f[i*2+b*2+1][j*2+1]='+';
    }
    for(i=1;i<=c;i++)for(j=1;j<=b;j++){
      f[i*2+b*2-j*2][a*2+j*2+1]='|';
      f[i*2+b*2-j*2+1][a*2+j*2+1]='+';
      f[i*2+b*2-j*2+2][a*2+j*2]='/';
    }
    for(i=1;i<=n;i++){
      for(j=1;j<=m;j++)putchar(f[i][j]);
      puts("");
    }
  }
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值