PC 110104 LC-Display 液晶显示屏//字符串 水题

来源:互联网 发布:照片涂鸦画画软件 编辑:程序博客网 时间:2024/05/01 09:31

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 ( 0<=n<=99, 999, 999) and s is the size in which it shall be displayed ( 1<=s<=10). 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 123453 678900 0

Sample Output

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

没啥可说的,一次AC
需要注意output的格式,没一个数字后面有一个空列,两个案例之间要有空行

#include <cstdio>#include <cstring>#include <iostream>using namespace std;char p1[]="- -- -----";char p2[]="| |  |  |  || ||  |    || || |";char p3[]="  ----- --";char p4[]="| |  ||    |  |  || |  || |  |";char p5[]="- -- -- --";int main(){int h, w, i, j, k, s, size, middle;char num[10];while (cin>>s>>num){if (s == 0 ) break;size =strlen(num);for (i=1; i<=s*2+3 ; i++){if (i==1)//part 1{for (j=0; j<size; j++){printf(" ");for (k=0; k<s; k++){cout<<p1[num[j]-48];}printf(" ");if (j<size-1) printf(" ");}}else if (1<i && i<1+s+1)//part 2 {for (j=0; j<size; j++){middle = (num[j]-48) * 3 + 1;cout<<p2[middle-1];for (k=0;k<s; k++){cout<<p2[middle];} cout<<p2[middle+1];if (j<size-1) printf(" ");}}else if (i == 1+s+1)//part 3{for (j=0; j<size; j++){printf(" ");for (k=0; k<s; k++){cout<<p3[num[j]-48];}printf(" ");if (j<size-1) printf(" ");}}else if (2+s < i && i<=2+ 2* s){for (j=0; j<size; j++){middle = (num[j]-48) * 3 + 1;cout<<p4[middle-1];for (k=0;k<s; k++){cout<<p4[middle];} cout<<p4[middle+1];if (j<size-1) printf(" ");}}else if (i==3+2*s){for (j=0; j<size; j++){printf(" ");for (k=0; k<s; k++){cout<<p5[num[j]-48];}printf(" ");if (j<size-1) printf(" ");}}cout<<endl;}cout<<endl;}return 0;}


原创粉丝点击