POJ 1102 LC-Display 模拟

本文详细探讨了POJ 1102 LC-Display的解题思路,主要使用C++进行模拟实现。通过实例输入和输出,解析了问题的关键步骤和解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

A friend of you has just bought a new computer. Until now, the most powerful computer he ever used has been a pocket calculator. Now, looking at his new computer, he is a bit disappointed, because he liked the LC-display of his calculator so much. So you decide to write a program that displays numbers in an LC-display-like style on his computer.

Input

The input contains several lines, one for each number to be displayed. Each line contains two integers s, n (1 <= s <= 10, 0 <= n <= 99 999 999), where n is the number to be displayed and s is the size in which it shall be displayed.

The input file will be terminated by a line containing two zeros. This line should not be processed.

Output

Output the numbers given in the input file in an LC-display-style using s "-" signs for the horizontal segments and s "|" signs for the vertical ones. Each digit occupies exactly s+2 columns and 2s+3 rows. (Be sure to fill all the white space occupied by the digits with blanks, also for the last digit.) There has to be exactly one column of blanks between two digits.

Output a blank line after each number. (You will find a sample of each digit in the sample output.)

Sample Input

2 12345
3 67890
0 0

Sample Output

      --   --        -- 
   |    |    | |  | | 
   |    |    | |  | | 
      --   --   --   -- 
   | |       |    |    |
   | |       |    |    |
      --   --        -- 

 ---   ---   ---   ---   --- 
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
 ---         ---   --- 
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
 ---         ---   ---   ---

输入的两个数分别是数字的尺寸 和要显示的数字组合  (注意:每两组数据空一行,每两个数字空一格)
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    char e[20][3]= {" -","-"};
    char q[33];
    char w[1][2]= {"|"};
    int m;
    int i,j,k;
    int t=0;
    while(scanf("%d%s",&m,q)!=EOF)
    {
        if(m==0)
            continue;
        if(t!=0)
            cout<<endl;
        t++;
        if(m==0&&q[0]=='0')
            break;
        for(i=0; i<=strlen(q)-1; i++)
        {
            if(i!=0)
                cout<<' ';
            if(q[i]=='1'||q[i]=='4')
            {
                for(j=1; j<=m+2; j++)
                    cout<<' ';
            }
            else
            {
                cout<<' ';
                for(j=1; j<=m; j++)
                {
                    cout<<e[1];
                }
                cout<<' ';
            }
        }
        cout<<endl;
        for(i=1; i<=m; i++)
        {
            for(k=0; k<=strlen(q)-1; k++)
            {
                if(k!=0)
                    cout<<' ';
                if(q[k]=='5'||q[k]=='6')
                {
                    cout<<w[0];
                    for(j=0; j<=m; j++)
                        cout<<' ';
                }
                else if(q[k]=='1'||q[k]=='2'||q[k]=='3'||q[k]=='7')
                {

                    for(j=0; j<=m; j++)
                        cout<<' ';
                    cout<<w[0];
                }
                else
                {
                    cout<<w[0];
                    for(j=0; j<m; j++)
                        cout<<' ';
                    cout<<w[0];
                }
            }
            cout<<endl;
        }
        for(i=0; i<strlen(q); i++)
        {
            if(i!=0)
                cout<<' ';
            if(q[i]=='1'||q[i]=='7'||q[i]=='0')
            {
                for(j=1; j<=m+2; j++)
                    cout<<' ';
            }
            else
            {
                cout<<' ';
                for(j=1; j<=m; j++)
                {
                    cout<<e[1];
                }
                cout<<' ';
            }
        }
        cout<<endl;
        for(i=1; i<=m; i++)
        {
            for(k=0; k<=strlen(q)-1; k++)
            {
                if(k!=0)
                    cout<<' ';
                if(q[k]=='2')
                {
                    cout<<w[0];
                    for(j=0; j<=m; j++)
                        cout<<' ';
                }
                else if(q[k]=='0'||q[k]=='8'||q[k]=='6')
                {
                    cout<<w[0];
                    for(j=0; j<m; j++)
                        cout<<' ';
                    cout<<w[0];
                }
                else
                {
                    for(j=0; j<=m; j++)
                        cout<<' ';
                    cout<<w[0];
                }
            }
            cout<<endl;
        }
        for(i=0; i<strlen(q); i++)
        {
            if(i!=0)
                cout<<' ';
            if(q[i]=='1'||q[i]=='7'||q[i]=='4')
            {
                for(j=1; j<=m+2; j++)
                    cout<<' ';
            }
            else
            {
                cout<<' ';
                for(j=1; j<=m; j++)
                {
                    cout<<e[1];
                }
                cout<<' ';
            }
        }
        cout<<endl;
    }
    return 0;
}

把没组数字分为五段 (三横二竖) 其实写出前两段 后三段也差不多了。。。
这次终于把速度提高了一点= =
显示出来的数字还挺 好看的 哈
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值