poj 1102(水题,有点麻烦)

#include<iostream>
#include<cstring>
using namespace std;
int main(){
    int s,cnt,tmp,col;
    char data[10];
    char ch[25][130];
    while(scanf("%d%s",&s,data)==2&&s){
        memset(ch,' ',sizeof ch);
        cnt = strlen(data);
        for(int i=0;i<cnt;i++){
            col = (3+s)*i;
            if(data[i]=='1'){
                for(int j=0;j<=1;j++){
                    for(int k=j*(s+1)+1;k<=j*(s+1)+s;k++){
                        ch[k][col+s+1] = '|';
                    }
                }
            }
            if(data[i]=='2'){
                for(int j=0;j<=2;j++){
                    for(int k=col+1;k<=col+s;k++){
                        ch[j*(s+1)][k] = '-';
                    }
                }
                for(int k=1;k<=s;k++){
                    ch[k][col+s+1] = '|';
                }
                for(int k=s+2;k<=s*2+1;k++){
                    ch[k][col] = '|';
                }
            }
            if(data[i]=='3'){
                for(int j=0;j<=2;j++){
                    for(int k=col+1;k<=col+s;k++){
                        ch[j*(s+1)][k] = '-';
                    }
                }
                for(int j=1;j<=2;j++){
                    for(int k=(j-1)*(s+1)+1;k<=(j-1)*(s+1)+s;k++){
                        ch[k][col+s+1] = '|';
                    }
                }
            }
            if(data[i]=='4'){
                for(int k=col+1;k<=col+s;k++){
                    ch[s+1][k] = '-';
                }
                for(int k=1;k<=s;k++){
                    ch[k][col] = '|';
                }
                for(int j=0;j<=1;j++){
                    for(int k=j*(s+1)+1;k<=j*(s+1)+s;k++){
                        ch[k][col+s+1] = '|';
                    }
                }
            }
            if(data[i]=='5'){
                for(int j=0;j<=2;j++){
                    for(int k=col+1;k<=col+s;k++){
                        ch[j*(s+1)][k] = '-';
                    }
                }
                for(int k=1;k<=s;k++){
                    ch[k][col] = '|';
                }
                for(int k=s+2;k<=2*s+1;k++){
                    ch[k][col+s+1] = '|';
                }
            }
            if(data[i]=='6'){
                for(int j=0;j<=2;j++){
                    for(int k=col+1;k<=col+s;k++){
                        ch[j*(s+1)][k] = '-';
                    }
                }
                for(int j=0;j<=1;j++){
                    for(int k=j*(s+1)+1;k<=j*(s+1)+s;k++){
                        ch[k][col] = '|';
                    }
                }
                for(int k=s+2;k<=2*s+1;k++){
                    ch[k][col+s+1] = '|';
                }
            }
            if(data[i]=='7'){
                for(int j=1;j<=2;j++){
                    for(int k=(j-1)*(s+1)+1;k<=(j-1)*(s+1)+s;k++){
                        ch[k][col+s+1] = '|';
                    }
                }
                for(int k=col+1;k<=col+s;k++){
                    ch[0][k] = '-';
                }
            }
            if(data[i]=='8'){
                for(int j=0;j<=2;j++){
                    for(int k=col+1;k<=col+s;k++){
                        ch[j*(s+1)][k] = '-';
                    }
                }
                for(int j=0;j<=1;j++){
                    for(int k=j*(s+1)+1;k<=j*(s+1)+s;k++){
                        ch[k][col] = '|';
                        ch[k][col+s+1] = '|';
                    }
                }
            }
            if(data[i]=='9'){
                for(int j=0;j<=2;j++){
                    for(int k=col+1;k<=col+s;k++){
                        ch[j*(s+1)][k] = '-';
                    }
                }
                for(int j=0;j<=1;j++){
                    for(int k=j*(s+1)+1;k<=j*(s+1)+s;k++){
                        ch[k][col+s+1] = '|';
                    }
                }
                for(int k=1;k<=s;k++){
                    ch[k][col] = '|';
                }
            }
            if(data[i]=='0'){
                for(int j=0;j<=1;j++){
                    for(int k=j*(s+1)+1;k<=j*(s+1)+s;k++){
                        ch[k][col] = '|';
                        ch[k][col+s+1] = '|';
                    }
                }
                for(int k=col+1;k<=col+s;k++){
                    ch[0][k] = '-';
                    ch[2*s+2][k] = '-';
                }
            }
        }
        for(int i=0;i<=2*s+2;i++){
            for(int j=0;j<(s+3)*cnt-1;j++){
                cout<<ch[i][j];
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
} 

 

posted @ 2021-12-01 13:15  智人心  阅读(32)  评论(0)    收藏  举报