zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    Windows python 鼠标键盘监控及控制
    python 执行adb shell 命令
    python Windows提示框
    判断function属于函数或方法
    生成不同时间下的LOG
    pyqt5 QCalendar类中常用的方法
    python字符串大小写转换
    configparser 模块的基本方法
    QGridLayout类中常用的方法
    Day049--jQuery的文档操作和事件介绍
  • 原文地址:https://www.cnblogs.com/cute/p/3396284.html
Copyright © 2011-2022 走看看