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 @   智人心  阅读(25)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
点击右上角即可分享
微信分享提示