HDU 1332(LC-Display)

模拟题,首先确定最小尺寸下每个数字的 LC 显示,然后根据给定的 s,将最小尺寸下的 LC 显示扩展 s 倍即可。

#include <iostream>
#include <cstring>
using namespace std;
const int MAXL = 10;

int digit[MAXL]; //将n的各位拆分
string LC[5][10] = { //最小尺寸下每个数字的LC显示
    " - ", "   ", " - ", " - ", "   ", " - ", " - ", " - ", " - ", " - ",
    "| |", "  |", "  |", "  |", "| |", "|  ", "|  ", "  |", "| |", "| |",
    "   ", "   ", " - ", " - ", " - ", " - ", " - ", "   ", " - ", " - ",
    "| |", "  |", "|  ", "  |", "  |", "  |", "| |", "  |", "| |", "  |",
    " - ", "   ", " - ", " - ", "   ", " - ", " - ", "   ", " - ", " - "
};

void output(int s, int n)
{
    if (n == 0)
        digit[MAXL - 1] = 0;
    else
    {
        for (int i = MAXL - 1; n > 0; i--)
        {
            digit[i] = n % 10;
            n /= 10;
        }
    }
    
    //将最小尺寸下的LC显示扩展s倍
    for (int row = 1; row <= (2 * s + 3); row++)
    {
        for (int i = 0; i < MAXL; i++)
            if (digit[i] != -1)
            {
                string line;
                if (row == 1)
                    line = LC[0][digit[i]];
                else if (1 < row && row < (s + 2))
                    line = LC[1][digit[i]];
                else if (row == (s + 2))
                    line = LC[2][digit[i]];
                else if ((s + 2) < row && row < (2 * s + 3))
                    line = LC[3][digit[i]];
                else
                    line = LC[4][digit[i]];

                cout << line[0];
                for (int j = 0; j < s; j++) //扩展s倍
                    cout << line[1];
                cout << line[2];

                if (i < (MAXL - 1)) //两个数字之间空一列
                    cout << " ";
            }
        cout << endl;
    }
    cout << endl;
}

int main()
{
    int s, n;
    while (cin >> s >> n)
    {
        if (s == 0 && n == 0)
            break;

        memset(digit, -1, sizeof(digit));
        output(s, n);  
    }
    return 0;
}

继续加油。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值