Problem L. Visual Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 159 Accepted Submission(s): 119
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
..+-+ ././| +-+.+ |.|/. +-+.. ....+-+-+-+-+-+-+ .../././././././| ..+-+-+-+-+-+-+.+ ./././././././|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/| +-+-+-+-+-+-+.+.+ |.|.|.|.|.|.|/|/. +-+-+-+-+-+-+.+.. |.|.|.|.|.|.|/... +-+-+-+-+-+-+....
Source
2018 Multi-University Training Contest 3
根据题意模拟即可。
#include<cstdio>
int main(){
int t;
scanf("%d",&t);
while(t--){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
char ans[1005][1005]={0};
for(int i=0;i<(c+b)*2+1;i++){
for(int j=0;j<(a+b)*2+1;j++){
ans[i][j]='.';
}
}
for(int i=0;i<b*2+1;i++){
if(i%2==0){
for(int j=0;j<a*2+1;j+=2){
ans[i][b*2-i+j]='+';
}
for(int j=1;j<a*2+1;j+=2){
ans[i][b*2-i+j]='-';
}
}else{
for(int j=0;j<a*2+1;j+=2){
ans[i][b*2-i+j]='/';
}
}
}
for(int i=b*2;i<(c+b)*2+1;i++){
if((i-b*2)%2==0){
for(int j=0;j<a*2+1;j+=2){
ans[i][j]='+';
}
for(int j=1;j<a*2+1;j+=2){
ans[i][j]='-';
}
}else{
for(int j=0;j<a*2+1;j+=2){
ans[i][j]='|';
}
}
}
for(int j=(a+b)*2;j>=a*2;j--){
if(((a+b)*2-j)%2==0){
for(int i=0;i<c*2+1;i+=2){
ans[(a+b)*2-j+i][j]='+';
}
for(int i=1;i<c*2+1;i+=2){
ans[(a+b)*2-j+i][j]='|';
}
}else{
for(int i=0;i<c*2+1;i+=2){
ans[(a+b)*2-j+i][j]='/';
}
}
}
for(int i=0;i<(c+b)*2+1;i++) printf("%s\n",ans[i]);
}
return 0;
}