pc110104 LC-Display

 

110104 LC-Display

 

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$ \le$n$ \le$99, 999, 999) and s is the size in which it shall be displayed ( 1$ \le$s$ \le$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 + 3rows. 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

 

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

 ---   ---   ---   ---   --- 
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
 ---         ---   ---       
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
 ---         ---   ---   ---
题意:就是很形象;
 
算法分析:这题就是一个模拟,要注意格式就是了,每两个案例间有个换行

View Code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#define S 15

using namespace std;

char number[11][2*S+4][S+3];
char ans[2*S+4][10*(S+3)];

void Init(int s)
{
memset(number,' ',sizeof(number));
int i;
//0
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
number[0][i][1]=number[0][i][s+2]='|';
}
for(i=2;i<=s+1;i++)
{
if(i==s+2) continue;
number[0][1][i]=number[0][2*s+3][i]='-';
}
//1
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
number[1][i][s+2]='|';
}
//2
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
if(i>s+2) number[2][i][1]='|';
if(i<s+2) number[2][i][s+2]='|';
}
for(i=2;i<=s+1;i++)
{
number[2][1][i]=number[2][s+2][i]=number[2][2*s+3][i]='-';
}
//3
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
number[3][i][s+2]='|';
}
for(i=2;i<=s+1;i++)
{
number[3][1][i]=number[3][s+2][i]=number[3][2*s+3][i]='-';
}
//4
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
if(i<s+2) number[4][i][1]='|';
number[4][i][s+2]='|';
}
for(i=2;i<=s+1;i++)
{
number[4][s+2][i]='-';
}
//5
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
if(i<s+2) number[5][i][1]='|';
if(i>s+2) number[5][i][s+2]='|';
}
for(i=2;i<=s+1;i++)
{
number[5][1][i]=number[5][s+2][i]=number[5][2*s+3][i]='-';
}
//6
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
number[6][i][1]='|';
if(i>s+2) number[6][i][s+2]='|';
}
for(i=2;i<=s+1;i++)
{
number[6][1][i]=number[6][s+2][i]=number[6][2*s+3][i]='-';
}
//7
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
number[7][i][s+2]='|';
}
for(i=2;i<=s+1;i++)
{
number[7][1][i]='-';
}
//8
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
number[8][i][1]=number[8][i][s+2]='|';
}
for(i=2;i<=s+1;i++)
{
number[8][1][i]=number[8][s+2][i]=number[8][2*s+3][i]='-';
}
//9
for(i=2;i<=2*s+2;i++)
{
if(i==s+2) continue;
if(i<s+2) number[9][i][1]='|';
number[9][i][s+2]='|';
}
for(i=2;i<=s+1;i++)
{
number[9][1][i]=number[9][s+2][i]=number[9][2*s+3][i]='-';
}

}

void work(int s,int a,int k)
{
int i,j;
for(i=1;i<=2*s+3;i++)
{
for(j=1;j<=s+2;j++)
ans[i][j+k*(s+3)]=number[a][i][j];
}
}

void output(int s,int len)
{
int i,j;
for(i=1;i<=2*s+3;i++)
{
for(j=1;j<=len*(s+3)-1;j++)
cout<<ans[i][j];
cout<<endl;
}
}

int main()
{
int s;
string n;
while(cin>>s>>n&&(s||n[0]-'0'))
{
Init(s);
memset(ans,' ',sizeof(ans));
int i;
for(i=0;i<n.length();i++)
work(s,n[i]-'0',i);
output(s,n.length());
}
return 0;
}

posted @ 2011-10-23 17:13  mtry  阅读(220)  评论(0)    收藏  举报