UVa 706 Problem: LC-Display (PC 110104)

/*
A friend of yours has just bought a new computer. Before this, the most powerful machine 
he ever used was a pocket calculator. He is a little disappointed because he liked the LCD 
display of his calculator more than the screen on his new computer! To make him happy, 
write a program that prints numbers in LCD display style.

Input

The input file contains several lines, one for each number to be displayed. Each line 
contains integers s and n, where n is the number to be displayed ( 0n99, 999, 999) and 
s is the size in which it shall be displayed ( 1s10). The input will be terminated by a 
line containing two zeros, which should not be processed.

Output

Print the numbers specified in the input file in an LCD 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, including the last digit. There must be exactly one column 
of blanks between two digits.

Output a blank line after each number. You will find an example of each digit in the 
sample output below.

Sample Input

2 12345
3 67890
0 0
Sample Output

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

 ---   ---   ---   ---   --- 
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
 ---         ---   ---       
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
 ---         ---   ---   ---
*/
//方法貌似搓了点,但是速度还可以
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <set>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max_S 12

using namespace std;
int S;
string NumStr;
char Matrix[2*Max_S + 3][(Max_S + 3)*8];//存放LCD显示数字,初始化全部为空格
//从上向下,从左向右,分成7笔画,分别为f1至f7
void f1(int k)
{
    for(int i = 2;i <= S + 1;i++)
    {
        Matrix[1][i + (S + 3)*k] = '-';
    }
}
void f2(int k)
{
    for(int i = 2;i <= S + 1;i++)
    {
        Matrix[i][1 + (S + 3)*k] = '|';
    }
}
void f3(int k)
{
    for(int i = 2;i <= S + 1;i++)
    {
        Matrix[i][S + 2 + (S + 3)*k] = '|';
    }
}
void f4(int k)
{
    for(int i = 2;i <= S + 1;i++)
    {
        Matrix[S + 2][i + (S + 3)*k] = '-';
    }
}
void f5(int k)
{
    for(int i = S + 3;i <= 2*S + 2;i++)
    {
        Matrix[i][1 + (S + 3)*k] = '|';
    }
}
void f6(int k)
{
    for(int i = S + 3;i <= 2*S + 2;i++)
    {
        Matrix[i][S + 2 + (S + 3)*k] = '|';
    }
}
void f7(int k)
{
    for(int i = 2;i <= S + 1;i++)
    {
        Matrix[2*S + 3][i + (S + 3)*k] = '-';
    }
}
//初始化Maxtrix
void init()
{
    for(int i = 1;i <= 2*S + 3;i++)
        {
            for(int j = 1;j <= (S + 3)*8 - 1;j++)
            {
                Matrix[i][j] = ' ';
            }
        }
}

//将数字字符转换成LCD显示,每个数字由对应笔画组成
void Change(char ch,int k)
{
    switch(ch)
    {
        case '0':{f1(k);f2(k);f3(k);f5(k);f6(k);f7(k);break;}
        case '1':{f3(k);f6(k);break;}
        case '2':{f1(k);f3(k);f4(k);f5(k);f7(k);break;}
        case '3':{f1(k);f3(k);f4(k);f6(k);f7(k);break;}
        case '4':{f2(k);f3(k);f4(k);f6(k);break;}
        case '5':{f1(k);f2(k);f4(k);f6(k);f7(k);break;}
        case '6':{f1(k);f2(k);f4(k);f5(k);f6(k);f7(k);break;}
        case '7':{f1(k);f3(k);f6(k);break;}
        case '8':{f1(k);f2(k);f3(k);f4(k);f5(k);f6(k);f7(k);break;}
        case '9':{f1(k);f2(k);f3(k);f4(k);f6(k);f7(k);break;}
    }

}
//显示整个数字
void Print()
{
        for(int i = 1;i <= 2*S + 3;i++)
        {
            for(int j = 1;j <= (S + 3)*NumStr.length() - 1;j++)
            {
                printf("%c",Matrix[i][j]);
            }
            printf("\n");
        }
}

int main()
{
    while(cin>>S>>NumStr,S != 0)
    {
        init();
        for(int i = 0;i < NumStr.length();i++)
        {
            Change(NumStr[i],i);
        }
        Print();
        printf("\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值