• PC/UVa 题号: 110104/706 LC-Display (液晶显示屏)题解


    #include <string>
    #include <iostream>
    #include <cstring>
    #include <algorithm>

    using namespace std;

    string numbers[5][10]={
    " - ", "   ", " - ", " - ", "   ", " - ", " - ", " - ", " - ", " - ",
    "| |", "  |", "  |", "  |", "| |", "|  ", "|  ", "  |", "| |", "| |", 
    "   ", "   ", " - ", " - ", " - ", " - ", " - ", "   ", " - ", " - ",
    "| |", "  |", "|  ", "  |", "  |", "  |", "| |", "  |", "| |", "  |", 
    " - ", "   ", " - ", " - ", "   ", " - ", " - ", "   ", " - ", " - ",
    };

    const int MAX_LEN=10;
    int num[MAX_LEN];

    //return number length
    int fill_num(int n)
    {
        memset(num, 0, sizeof(num));
        int i=0;
        do
        {
            num[i++]=n%10;
            n/=10;
        }while(n!=0);

        reverse(num, num+i);
        return i;

    }
    void cout_a_row(int s, string n)
    {
        cout<<n[0];
        for(int i=0;i<s;i++)
            cout<<n[1];
        cout<<n[2];
    }

    void print_num(int s, int n)
    {

        int len=fill_num(n);
        //cout<<len<<endl;

        for(int row=0;row<(3+2*s);row++)
        {
            //输出各个数字的一行
            for(int i=0;i<len;i++)
            {
                int real_row;
                //head
                if(row==0)
                {
                    real_row=0;
                }
                //head-mid
                if(row>0 && row<(3+2*s)/2)
                {
               
                    real_row=1;
                }
                //mid
                if(row==(3+2*s)/2)
                {
                    real_row=2;
                }
                if(row>(3+2*s)/2 && row<(3+2*s-1))
                {
                    real_row=3;
                }
                //tail
                if(row==(3+2*s-1))
                {
                    real_row=4;
                }
               
                cout_a_row(s, numbers[real_row][num[i]]);
                (i==len-1)?(cout<<endl):(cout<<" ");
            }
        }
        cout<<endl;
    }

    int main()
    {
    #if 0
        print_num(1, 1234567890);
        print_num(3, 1234567890);
        print_num(5, 1234567890);
        print_num(7, 1234567890);
    #endif
        int s,num;
        while(cin>>s>>num, s||num)
        {
            print_num(s, num);
        }
        return 0;
    }

  • 相关阅读:
    设计模式之适配器模式温故知新(九)
    设计模式之策略模式总结(八)
    设计模式之观察者模式, 个人感觉相当的重要(七)
    设计模式之抽象工厂模式读后(六)
    设计模式之工厂模式详细读后感TT!(五)
    设计模式之简单工厂模式, 加速(四)
    设计模式之代理模式笔记(三)
    设计模式之单例模式读后思考(二)
    为什么要用设计模式?先看看6大原则(一)
    Codeforces_835
  • 原文地址:https://www.cnblogs.com/cute/p/3396284.html
Copyright © 2020-2023  润新知