Problem L. Visual Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 455 Accepted Submission(s): 322
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
模拟画立方体,注意一下前缀点和后缀点即可
#include<bits/stdc++.h>
#define maxn 100010
#define ll long long
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int l,w,h;
scanf("%d%d%d",&l,&w,&h);
// char c[200][200];
int m=2*l+1+2*w;
int n=2*h+1+2*w;
int k=2*w;
int T1=k+1,T2=n-k;
for(int i=1;i<=n;i++)
{
if(i<T1)
{
int d=k-i+1;
int dr=k-(n-i);
dr=max(0,dr);
//cout<<d<<endl;
if(i%2)
{
int t=l;
for(int j=1;j<=m;j++)
{
if(j>m-dr) { putchar('.');continue; }
if(d){putchar('.');d--;}
else {if(j%2)putchar('+');
else { if(t){putchar('-');t--;}
else putchar('.');
}
}
}
putchar('\n');
}
else
{
int s=i/2-1;
int d1=0;
for(int j=1;j<=m;j++)
{
if(j>m-dr) { putchar('.');continue; }
if(d){putchar('.');d--;}
else { if(j%2==0)putchar('/');
else {
if(d1<l){putchar('.');d1++;}
else putchar('|');
}
}
}
putchar('\n');
}
}
else if(i>=T1&&i<=T2)
{
int t=l;
for(int j=1;j<=m;j++)
{
if(i%2){ if(j%2){putchar('+'); }
else{ if(t){putchar('-'); t--;}
else putchar('.');
}
}
else{ if(j%2){putchar('|'); }
else{ if(t){putchar('.'); t--;}
else putchar('/');
}
}
}
putchar('\n');
}
else
{
int d=k-(n-i);
int t=l;
if(i%2)
{
for(int j=1;j<=m;j++)
{
if(j>m-d) putchar('.');
else{ if(j%2) putchar('+');
else { if(t){ putchar('-');t--; }
else putchar('.');
}
}
}
putchar('\n');
}
else{
for(int j=1;j<=m;j++)
{
if(j>m-d) putchar('.');
else{ if(j%2) putchar('|');
else { if(t){ putchar('.');t--; }
else putchar('/');
}
}
}
putchar('\n');
}
}
}
}
return 0;
}