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;
    }

  • 相关阅读:
    逆序数 POJ 2299 Ultra-QuickSort
    DP URAL 1244 Gentlemen
    找规律 SGU 107 987654321 problem
    找规律 SGU 126 Boxes
    DP VK Cup 2012 Qualification Round D. Palindrome pairs
    模拟 Coder-Strike 2014
    模拟 Codeforces Round #203 (Div. 2) C. Bombs
    DFS HDOJ 2614 Beat
    最短路(Floyd_Warshall) POJ 2240 Arbitrage
    最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
  • 原文地址:https://www.cnblogs.com/cute/p/3396284.html
Copyright © 2011-2022 走看看