zoukankan      html  css  js  c++  java
  • 计蒜客:显示屏输出

    蒜头君有一块数码管显示屏,只能显示数字。每个数字的显示如下。每 

    给这道题跪了,注意数据的存储,和访问。具体解释 看代码注释

    #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]!='';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;
    }
    
  • 相关阅读:
    软考相关试题
    qt中的toUtf8, toLatin1, Local8bit, toUcs4(转)
    qt的中文乱码问题
    《左耳听风》-ARTS-打卡记录-第八周
    杂题
    图论
    基础数据结构
    整除
    同余
    常用数学
  • 原文地址:https://www.cnblogs.com/qie-wei/p/12094113.html
Copyright © 2011-2022 走看看