Counter: display output

Mr. Suantou has a digital tube display, which can only display numbers. The display of each number is as follows. each 

Kneel to this question, pay attention to data storage and access. See the code comments for specific explanations

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
char pic[10][5][2]=
{
    //  第1行  第2行   第3行  第4行   第5行(1,3,5行,也就是日字的三横只有一笔,所以pic[1~10][{1,3,5}][1]=' ')
    {
   
   {'-',' '},{'|','|'},{' ',' '},{'|','|'},{'-',' '}},//数字0的第一行,第二行,第三行……
    {
   
   {' ',' '},{' ','|'},{' ',' '},{' ','|'},{' ',' '}},//数字1的第一行,第二行,第三行……
    {
   
   {'-',' '},{' ','|'},{'-',' '},{'|',' '},{'-',' '}},
    {
   
   {'-',' '},{' ','|'},{'-',' '},{' ','|'},{'-',' '}},
    {
   
   {' ',' '},{'|','|'},{'-',' '},{' ','|'},{' ',' '}},
    {
   
   {'-',' '},{'|',' '},{'-',' '},{' ','|'},{'-',' '}},
    {
   
   {'-',' '},{'|',' '},{'-',' '},{'|','|'},{'-',' '}},
    {
   
   {'-',' '},{' ','|'},{' ',' '},{' ','|'},{' ',' '}},
    {
   
   {'-',' '},{'|','|'},{'-',' '},{'|','|'},{'-',' '}},
    {
   
   {'-',' '},{'|','|'},{'-',' '},{' ','|'},{'-',' '}}
};
int main()
{
   int ex,cnt=0,num[10];
   char str[100];cin>>ex;getchar();
   /*while(scanf("%c",&ch)==1&&ch!=10)
   {
       num[cnt]=ch-'0';
       cnt++;
   }*/
   cin>>str;
   for(int i=0;str[i]!='\0';i++)
     num[i]=str[i]-'0';
    cnt = strlen(str);
    
   for(int row=1;row<=5;row++)//日字一共有5行
   {
       if(row%2==1)//日字的三横
       {
           for(int i=0;i<cnt;i++)//数字
           {
                cout<<" ";
                for(int j=0;j<ex;j++)//放大的倍数
                    cout<<pic[num[i]][row-1][0];
                cout<<" ";
                if(i!=cnt-1)
                    cout<<" ";
           }
           cout<<endl;
       }else{
            for(int i=0;i<ex;i++)//'|'放大的倍数
            {
                for(int j=0;j<cnt;j++)//数字
                {
                    char a,b;
                    a=pic[num[j]][row-1][0];
                    b=pic[num[j]][row-1][1];
                    cout<<a;
                    for(int k=0;k<ex;k++)
                        cout<<" ";
                    cout<<b;
                    if(j!=cnt-1)
                    cout<<" ";
                }
                cout<<endl;
            }
       }
   }

    return 0;
}

 

Guess you like

Origin blog.csdn.net/qie_wei/article/details/89011832