您的位置:首页 > 其它

LC-Display

2013-09-11 14:03 190 查看

LC-Display

Problem DescriptionA friend of you has just bought a new computer. Until now, the mostpowerful computer he ever used has been a pocket calculator. Now,looking at his new computer, he is a bit disappointed, because heliked the LC-display of his calculator so much. So you decide towrite a program that displays numbers in an LC-display-like styleon his computer.  InputThe input contains several lines, one for each number to bedisplayed. Each line contains two integers s, n (1<= s <= 10, 0 <= n<= 99 999 999), where n is the number to bedisplayed and s is the size in which it shall bedisplayed. The input file will be terminated by a line containing two zeros.This line should not be processed.  OutputOutput the numbers given in the input file in an LC-display-styleusing s ``-'' signs for the horizontal segments and s ``|'' signsfor the vertical ones. Each digit occupies exactly s+2 columns and2s+3 rows. (Be sure to fill all the white space occupied by thedigits with blanks, also for the last digit.) There has to beexactly one column of blanks between twodigits. Output a blank line after each number. (You will find a sample ofeach digit in the sample output.)  Sample Input
212345 367890 0 0 Sample Output
    --  --       --  |   |   ||  ||  |   |   | |  ||     --  --  --  --   ||      |   |   |   ||      |   |   |     --  --       --    ---  ---  ---  ---  ---|        | |   ||   ||  ||        | |   ||   ||  ||        | |   ||   ||  | ---        ---  ---|  |    | |  |    | |  ||  |    | |  |    | |  ||  |    | |  |    | |  | ---        ---  ---  ---  #include<stdio.h>#include<string.h>char map[5][50]={       {" -      -   -      -  -   -   -  - "},       {"| |   |  |   | | | |  |     | | | | |"},       {"        -  -   -   -  -      -   - "},       {"| |   | |    |   |  | | |   | | |  |"},       {" -      -   -      -  -      -   - "}};  //记录大小为1数字,以方便在输出时选择输出的符号,减少判断   char str[30];ints;void Display( int r){   int index,i,j;intm;m=strlen(str);   for( i=0; i<m-1; i++)   {       index = (str[i] -'0')*4; //求出要输出的数字的下标                   printf("%c", map[r][index]); //第一个符号总是按原型输出就可以了              for(j = 0; j<s;j++)   //不难看出对于每一行只要把中间的符号按s次输出就行了。              {          printf("%c", map[r][index+1]);       }       printf("%c",map[r][index+2]);  //输出最后一个符号,它在点阵总的下标是index+2              printf(" ");                 }       index = (str[m-1] -'0')*4;                    printf("%c", map[r][index]);               for(j = 0; j<s;j++)                {          printf("%c", map[r][index+1]);       }       printf("%c",map[r][index+2]);//输出每个数字后的空格,最后一个数字的空格不要输出。       printf("\n");   }intmain(){   int i,j;   while(scanf("%d",&s), s!=0)   {       scanf("%s",str);       for(i = 0; i <5; i++)   //根据输出的特点,我们只能按行输出,因此我们按行处理                        {          if(i== 0 || i == 2 || i == 4)  //第一行,中间行,和末行,直接处理                                 {             Display(i);          }          else         //否则,对‘|’存在的row,我们要s次输出                              {              for( j = 0;j < s; j++)             {                 Display(i);                         }          }       }       printf("\n");   }   return 0;} 

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: