zoukankan      html  css  js  c++  java
  • POJ 1102

    Description

    A friend of you has just bought a new computer. Until now, the most powerful computer he ever used has been a pocket calculator. Now, looking at his new computer, he is a bit disappointed, because he liked the LC-display of his calculator so much. So you decide to write a program that displays numbers in an LC-display-like style on his computer.

    Input

    The input contains several lines, one for each number to be displayed. Each line contains two integers s, n (1 <= s <= 10, 0 <= n <= 99 999 999), where n is the number to be displayed and s is the size in which it shall be displayed. 

    The input file will be terminated by a line containing two zeros. This line should not be processed.

    Output

    Output the numbers given in the input file in an LC-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, also for the last digit.) There has to be exactly one column of blanks between two digits. 

    Output a blank line after each number. (You will find a sample of each digit in the sample output.)

    Sample Input

    2 12345
    3 67890
    0 0

    Sample Output

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

    Source

     
    看看sample input和sample output就知道它让你干嘛了……所以一行行暴力一点的输出就好
     1 #include<stdio.h>
     2 #include<string.h>
     3 void row_0(int n){int i;for(i=1;i<=n+2;i++) printf(" ");}
     4 void row_1(int n){int i;printf(" ");for(i=1;i<=n;i++) printf("-");printf(" ");}
     5 void col_l(int n){int i;printf("|");for(i=1;i<=n+1;i++) printf(" ");}
     6 void col_r(int n){int i;for(i=1;i<=n+1;i++) printf(" ");printf("|");}
     7 void col_b(int n){int i;printf("|");for(i=1;i<=n;i++) printf(" ");printf("|");}
     8 void display(int num[],int n)
     9 {
    10     int r,c,i;
    11     for(r=1;r<=2*n+3;r++){
    12         //输出三个衡横行 
    13         if((r-1)%(n+1)==0)
    14         for(c=0;num[c]>=0;c++){
    15             if(num[c]==2 || num[c]==3 || num[c]==5 || num[c]==6 || num[c]==8 || num[c]==9) row_1(n);
    16             if(num[c]==1) for(i=1;i<=n+2;i++) printf(" ");
    17             if(num[c]==4){
    18                 if((r-1)/(n+1)==1) row_1(n);
    19                 else row_0(n);
    20             }
    21             if(num[c]==7){
    22                 if((r-1)/(n+1)==0) row_1(n);
    23                 else row_0(n);
    24             }
    25             if(num[c]==0){
    26                 if((r-1)/(n+1)==1) row_0(n);
    27                 else row_1(n);
    28             }
    29             printf(" ");
    30         }
    31         //输出上竖行 
    32         if(r>1 && r<n+2)
    33         for(c=0;num[c]>=0;c++){
    34             if(num[c]==5 || num[c]==6) col_l(n);
    35             if(num[c]==1 || num[c]==2 || num[c]==3 || num[c]==7) col_r(n);
    36             if(num[c]==4 || num[c]==8 || num[c]==9 || num[c]==0) col_b(n);
    37             printf(" ");
    38         }
    39         //输出下竖行 
    40         if(r>n+2 && r<2*n+3)
    41         for(c=0;num[c]>=0;c++){
    42             if(num[c]==2) col_l(n);
    43             else if(num[c]==0 || num[c]==6 || num[c]==8) col_b(n);
    44             else col_r(n);
    45             printf(" ");
    46         }
    47         
    48         printf("
    ");
    49     }
    50 }
    51 int main()
    52 {
    53     int i,n,num[9];char temp[9];
    54     while( scanf("%d %s",&n,&temp) && n!=0 ){
    55         memset(num,-1,sizeof(num));
    56         for(i=0;temp[i];i++){
    57             num[i]=temp[i]-'0';
    58         }
    59         display(num,n);
    60         if(n!=0) printf("
    ");
    61     }
    62 }
  • 相关阅读:
    4.9cf自训9..
    数位dp-入门模板题 hdu2089
    熟能生巧 汽车停车入位技巧解析-倒车入库--侧边停车
    MyBatis参数传入集合之foreach动态sql
    jquery如何判断checkbox(复选框)是否被选中
    Mybatis关联查询(嵌套查询)
    Mysql 分页语句Limit用法
    $.ajax返回的JSON格式的数据后无法执行success的解决方法
    JavaWeb学习总结(十二)——Session
    Spring MVC中Session的正确用法之我见
  • 原文地址:https://www.cnblogs.com/dilthey/p/6804188.html
Copyright © 2011-2022 走看看