zoukankan      html  css  js  c++  java
  • 烟大 Contest1024

    Problem D: LC-Display

    Time Limit: 1 Sec  Memory Limit: 64 MB
    Submit: 14  Solved: 3
    [Submit][Status][Web Board]

    Description

    A friend of yours has just bought a new computer. Before this, the most powerful machine he ever used was a pocket calculator. He is a little disappointed because he liked the LCD display of his calculator more than the screen on his new computer! To make him happy, write a program that prints numbers in LCD display style.

    Input

    The input file contains several lines, one for each number to be displayed. Each line contains integers s and n, where n is the number to be displayed ( 0n99, 999, 999) and s is the size in which it shall be displayed ( 1s10). The input will be terminated by a line containing two zeros, which should not be processed

    Output

    Print the numbers specified in the input file in an LCD display-style using s ``-'' signs for the horizontal segments and s ``|'' signs for the vertical ones. Each digit occupies exactly s + 2 columns and 2s + 3 rows. Be sure to fill all the white space occupied by the digits with blanks, including the last digit. There must be exactly one column of blanks between two digits. Output a blank line after each number. You will find an example of each digit in the sample output below.

    Sample Input

    2 12345
    3 67890
    0 0

    Sample Output

          --   --        -- 
       |    |    | |  | | 
       |    |    | |  | | 
          --   --   --   -- 
       | |       |    |    |
       | |       |    |    |
          --   --        -- 
    
     ---   ---   ---   ---   --- 
    |         | |   | |   | |   |
    |         | |   | |   | |   |
    |         | |   | |   | |   |
     ---         ---   --- 
    |   |     | |   |     | |   |
    |   |     | |   |     | |   |
    |   |     | |   |     | |   |
     ---         ---   ---   ---

    HINT

    杭电1332


      模拟题。这道题是在控制台中以计算器的显示形式显示指定尺寸大小的一串数字。

      我的做法是提前写好数字的模板(因为尺寸不确定,所以要把数字做成模板),存放在一个三维数组中(数字,行,列)。输入尺寸和数字串后,将数字的模板组合起来,然后解析成指定尺寸的数字输出出来。

    My code:

      1 //这是一道模拟题
      2 //模拟计算器的形式在控制台中输出数字
      3 
      4 #include <iostream>
      5 #include <string.h>
      6 using namespace std;
      7 
      8 int a[10][5][3]=
      9 {
     10 {//0
     11 0,2,0,
     12 1,3,1,
     13 0,3,0,
     14 1,3,1,
     15 0,2,0
     16 }
     17 ,{//1
     18 0,3,0,
     19 0,3,1,
     20 0,3,0,
     21 0,3,1,
     22 0,3,0}
     23 ,{//2
     24 0,2,0,
     25 0,3,1,
     26 0,2,0,
     27 1,3,0,
     28 0,2,0
     29 }
     30 ,{//3
     31 0,2,0,
     32 0,3,1,
     33 0,2,0,
     34 0,3,1,
     35 0,2,0
     36 }
     37 ,{//4
     38 0,3,0,
     39 1,3,1,
     40 0,2,0,
     41 0,3,1,
     42 0,3,0
     43 }
     44 ,{//5
     45 0,2,0,
     46 1,3,0,
     47 0,2,0,
     48 0,3,1,
     49 0,2,0
     50 }
     51 ,{//6
     52 0,2,0,
     53 1,3,0,
     54 0,2,0,
     55 1,3,1,
     56 0,2,0
     57 }
     58 ,{//7
     59 0,2,0,
     60 0,3,1,
     61 0,3,0,
     62 0,3,1,
     63 0,3,0
     64 }
     65 ,{//8
     66 0,2,0,
     67 1,3,1,
     68 0,2,0,
     69 1,3,1,
     70 0,2,0
     71 }
     72 ,{//9
     73 0,2,0,
     74 1,3,1,
     75 0,2,0,
     76 0,3,1,
     77 0,2,0
     78 }
     79 };
     80 /*
     81 0是一个空格
     82 1是size个竖杠
     83 2是size个横杠
     84 3是size个虚横杠
     85 */
     86 int b[6][1001];
     87 int main()
     88 {
     89     string l;
     90     int size;
     91     while(cin>>size){
     92         cin>>l;
     93         if(size==0 && l=="0") break;
     94         int length=l.length();
     95         //组合数字模板在数组b中
     96         for(int i=1;i<=5;i++){   //循环行
     97             int f=1;    //组合数组b的第一个开始赋值
     98             for(int j=1;j<=length;j++){ //循环数字
     99                 int num=l[j-1]-'0';
    100                 for(int k=0;k<3;k++){
    101                     b[i][f]=a[num][i-1][k];
    102                     f++;
    103                 }
    104                 b[i][f]=0;
    105                 f++;
    106             }
    107         }
    108         /*输出组合好的数字模板
    109         for(int i=1;i<=5;i++){
    110             for(int j=1;j<=3*length+length-1;j++)
    111                 cout<<b[i][j];
    112             cout<<endl;
    113         }
    114         */
    115         //将数字模板解析成数字
    116         //0输出一个空格
    117         //1输出size行竖杠
    118         //2输出size个横杠
    119         //3输出size行空格
    120         int count = 0;
    121         for(int i=1;i<=5;i++){//循环行
    122             for(int j=1;j<=3*length+length-1;j++){
    123                 //if(j==3*length+length-1 && b[i][j]==0)
    124                 //    continue;
    125                 if(i%2!=0){
    126                     switch(b[i][j]){
    127                     case 0:
    128                         cout<<' ';
    129                         break;
    130                     case 2:
    131                         for(int k=0;k<size;k++)
    132                             cout<<'-';
    133                         break;
    134                     case 3:
    135                         for(int k=0;k<size;k++)
    136                             cout<<' ';
    137                         break;
    138                     }
    139                 }
    140                 else{
    141                     switch(b[i][j]){
    142                     case 0:
    143                         cout<<' ';break;
    144                     case 3:
    145                         for(int k=0;k<size;k++)
    146                             cout<<' ';
    147                         break;
    148                     case 1:
    149                         cout<<'|';break;
    150                     }
    151                 }
    152             }
    153             cout<<endl;
    154             if(i%2==0){  //如果改行是偶数行,且输出次数再输出一遍
    155                 ++count;    //如果是偶数行,已经输出一遍了,count+1
    156                 if(count<size)
    157                     --i;
    158             }
    159             else
    160                 count=0;
    161         }
    162         cout<<endl;
    163     }
    164     return 0;
    165 }

     Freecode : www.cnblogs.com/yym2013

  • 相关阅读:
    LeetCode对撞指针汇总
    167. Two Sum II
    215. Kth Largest Element in an Array
    2018Action Recognition from Skeleton Data via Analogical Generalization over Qualitative Representations
    题解 Educational Codeforces Round 84 (Rated for Div. 2) (CF1327)
    题解 JZPKIL
    题解 八省联考2018 / 九省联考2018
    题解 六省联考2017
    题解 Codeforces Round #621 (Div. 1 + Div. 2) (CF1307)
    题解Codeforces Round #620 (Div. 2)
  • 原文地址:https://www.cnblogs.com/yym2013/p/3224928.html
Copyright © 2011-2022 走看看