poj 1102 LC-Display显示器

本文介绍了一个用于模拟计算器风格数字显示的程序。通过使用特定的字符组合,该程序可以将任意数字以LC-display风格展示出来。适用于不同尺寸的数字显示需求。

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

/**
LC-Display
Time Limit: 1000MS  Memory Limit: 10000K 
Total Submissions: 14139  Accepted: 5623 

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

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

 ---   ---   ---   ---   --- 
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
 ---         ---   --- 
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
 ---         ---   ---   ---
Source

Mid-Central European Regional Contest 1999


显示器查看提交统计提问总时间限制: 1000ms内存限制: 65536kB
描述
你的一个朋友买了一台电脑。他以前只用过计算器,因为电脑的显示器上显示的数字的样子和计算器是不一样,所以当他使用电脑的时候会比较郁闷。
为了帮助他,你决定写一个程序把在电脑上的数字显示得像计算器上一样。
输入
输入包括若干行,每行表示一个要显示的数。每行有两个整数s和n (1 <= s <= 10, 0 <= n <= 99999999),这里n是要显示的数,s是要显示的数的尺寸。

如果某行输入包括两个0,表示输入结束。这行不需要处理。
输出
显示的方式是:用s个'-'表示一个水平线段,用s个'|'表示一个垂直线段。这种情况下,每一个数字需要占用s+2列和2s+3行。另外,在两个数字之间要
输出一个空白的列。在输出完每一个数之后,输出一个空白的行。注意:输出中空白的地方都要用空格来填充。
样例输入
2 12345
3 67890
0 0
样例输出
      --   --        --
   |    |    | |  | |
   |    |    | |  | |
      --   --   --   --
   | |       |    |    |
   | |       |    |    |
      --   --        --

 ---   ---   ---   ---   ---
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
 ---         ---   ---
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
 ---         ---   ---   ---
提示
数字(digit)指的是0,或者1,或者2……或者9。
数(number)由一个或者多个数字组成。
*/

#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main()
{
    int s = 0;
    char num[10];
    bool ns[10][5][2] =
       {{1,0,1,1,0,0,1,1,1,0},
        {0,0,0,1,0,0,0,1,0,0},
        {1,0,0,1,1,0,1,0,1,0},
        {1,0,0,1,1,0,0,1,1,0},
        {0,0,1,1,1,0,0,1,0,0},
        {1,0,1,0,1,0,0,1,1,0},
        {1,0,1,0,1,0,1,1,1,0},
        {1,0,0,1,0,0,0,1,0,0},
        {1,0,1,1,1,0,1,1,1,0},
        {1,0,1,1,1,0,0,1,1,0}
    };


    while(true)
    {
        scanf("%d%s", &s, num);
        if(!s) break;
        //printf("%d\n",strlen(num));
        for(int j = 0; j < 5; ++j)
        {
            if(j % 2 == 0)
            {

                for(int i = 0; i < strlen(num); ++i)//数字
                {
                    printf(" ");

                        for(int k = 0; k < s; ++k)
                           {if(ns[num[i] - '0'][j][0]) printf("-");
                           else printf(" ");}
                    printf(" ");
                    if(i != strlen(num) - 1) printf(" ");
                }
                printf("\n");
            }
            else
            {
                for(int t = 0; t < s ; ++t)
                {
                    for(int i = 0; i < strlen(num); ++i)//数字
                    {
                        if(ns[num[i] - '0'][j][0]) printf("|");
                        else printf(" ");
                        for(int k = 0; k < s; ++k) printf(" ");
                        if(ns[num[i] - '0'][j][1]) printf("|");
                        else printf(" ");
                        if(i != strlen(num) - 1) printf(" ");
                    }
                printf("\n");
                }
            }
        }
        printf("\n");
    }
    return 0;
}

转载于:https://my.oschina.net/locusxt/blog/133531

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值