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 }
  • 相关阅读:
    网页的资源加载优化
    Object.prototype.toString的应用
    判断一个字符串中出现次数最多的字符,并统计字数
    toString()和toLocaleString()有什么区别
    响应式网站布局要适应的当下主流手机屏幕的各个版本的分辨率有哪些(media query)
    handlebars用法
    算符优先分析及其简单代码实现
    OpenGL:使用顶点数组法绘制正六面体
    算法设计:两种快速排序代码实现
    c#简易学生信息管理系统
  • 原文地址:https://www.cnblogs.com/dilthey/p/6804188.html
Copyright © 2011-2022 走看看