题解
看到别人都用了什么结构来存储,我就比较简单粗暴了,直接按 行 - 字 - 列 的顺序依次考虑输出对象。
想清楚了其实不难,就是稍微繁杂了点,有点像小学奥赛题…
Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int n,m;
int cot[256];
void pr(int k){
for(int j=1;j<=2*k+3;j++){// row
for(int i=0;i<n;i++){ // each num
for(int pos=1;pos<=k+3;pos++){ // col
if(pos==k+3) {
cout<<" ";// last col space
break;
}
if(j==1){ // head
if( pos==1 || pos==k+2) cout<<" ";
else{
if(cot[i]==1 || cot[i]==4) cout<<" ";
else cout<<"-";
}
}
if( j>1 && j<k+2 ){ // up body
if(pos>1 && pos <k+2) cout<<" ";
else{
if(pos==1){
if(cot[i]==1||cot[i]==2||
cot[i]==3||cot[i]==7) cout<<" ";
else cout<<"|";
}else{
if(cot[i]==5||cot[i]==6) cout<<" ";
else cout<<"|";
}
}
}
if( j== k+2 ){// waist
if(pos==1||pos==k+2) cout<<" ";
else{
if(cot[i]==1||cot[i]==7||cot[i]==0) cout<<" ";
else cout<<"-";
}
}
if( j>k+2 && j< 2*k+3){// down body
if(pos>1 && pos <k+2) cout<<" ";
else{
if(pos==1){
if(cot[i]==2||cot[i]==6||
cot[i]==8||cot[i]==0) cout<<"|";
else cout<<" ";
}
else{
if(cot[i]==2) cout<<" ";
else cout<<"|";
}
}
}
if(j==2*k+3){// foot
if(pos==1||pos==k+2) cout<<" ";
else{
if(cot[i]==1||cot[i]==4||
cot[i]==7) cout<<" ";
else cout<<"-";
}
}
}
}
cout<<endl;
}
}
int main(){
int k;
cin>>k;
string str;
cin>>str;
n = str.size();
for(int i=0;i<n;i++) {
cot[i] = str[i]-'0';
}
pr(k);
return 0;
}