LC-Display
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
-- -- --
| | | | | |
| | | | | |
-- -- -- --
| | | | |
| | | | |
-- -- --
--- --- --- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- --- ---
代码:
#include<stdio.h>
#include<string.h>
char map[10][30][30];
void row1(int n, char * a, char x, char y)
{
// - //| |
a[0] = x, a[n+1] = x, a[n+2] = 0;
for (int i = 1; i <= n; i++)
{
a[i] = y;
}
}
void row2(int n, char * a)
{
//|
a[0] = '|', a[n+2] = 0;
for (int i = 1; i <= n + 1; i++)
{
a[i] = ' ';
}
}
void row4(int n, char * a)
{// |
a[n+1] = '|', a[n+2] = 0;
for (int i = 0; i <= n; i++)
{
a[i] = ' ';
}
}
void row3(int n, char * a)
{
// //
int i;
for (i = 0; i <= n + 1; i++)
{
a[i] = ' ';
}
a[i] = 0;
}
void set(int num, int n, char a[][30])
{
int i;
if (num == 1)
{
row3(n, a[0]), row3(n, a[n+1]), row3(n, a[2*n+2]);
for (i = 1; i < 2 * n + 2; i++)
{
if (i != n + 1)
{
row4(n, a[i]);
}
}
}
else if (num == 2)
{
row1(n, a[0], ' ', '-'), row1(n, a[n+1], ' ', '-'), row1(n, a[2*n+2], ' ', '-');
for (i = 1; i <= n; i++)
{
row4(n, a[i]);
}
for (i++; i < 2 * n + 2; i++)
{
row2(n, a[i]);
}
}
else if (num == 3)
{
row1(n, a[0], ' ', '-'), row1(n, a[n+1], ' ', '-'), row1(n, a[2*n+2], ' ', '-');
for (i = 1; i < 2 * n + 2; i++)
{
if (i != n + 1)
{
row4(n, a[i]);
}
}
}
else if (num == 4)
{
row3(n, a[0]), row1(n, a[n+1], ' ', '-'), row3(n, a[2*n+2]);
for (i = 1; i <= n; i++)
{
row1(n, a[i], '|', ' ');
}
for (i++; i < 2 * n + 2; i++)
{
row4(n, a[i]);
}
}
else if (num == 5)
{
row1(n, a[0], ' ', '-'), row1(n, a[n+1], ' ', '-'), row1(n, a[2*n+2], ' ', '-');
for (i = 1; i <= n; i++)
{
row2(n, a[i]);
}
for (i++; i < 2 * n + 2; i++)
{
row4(n, a[i]);
}
}
else if (num == 6)
{
row1(n, a[0], ' ', '-'), row1(n, a[n+1], ' ', '-'), row1(n, a[2*n+2], ' ', '-');
for (i = 1; i <= n; i++)
{
row2(n, a[i]);
}
for (i++; i < 2 * n + 2; i++)
{
row1(n, a[i], '|', ' ');
}
}
else if (num == 7)
{
row1(n, a[0], ' ', '-'), row3(n, a[n+1]), row3(n, a[2*n+2]);
for (i = 1; i < 2 * n + 2; i++)
{
if (i != n + 1)
{
row4(n, a[i]);
}
}
}
else if (num == 8)
{
row1(n, a[0], ' ', '-'), row1(n, a[n+1], ' ', '-'), row1(n, a[2*n+2], ' ', '-');
for (i = 1; i < 2 * n + 2; i++)
{
if (i != n + 1)
{
row1(n, a[i], '|', ' ');
}
}
}
else if (num == 9)
{
row1(n, a[0], ' ', '-'), row1(n, a[n+1], ' ', '-'), row1(n, a[2*n+2], ' ', '-');
for (i = 1; i <= n; i++)
{
row1(n, a[i], '|', ' ');
}
for (i++; i < 2 * n + 2; i++)
{
row4(n, a[i]);
}
}
else if (num == 0)
{
row1(n, a[0], ' ', '-'), row3(n, a[n+1]), row1(n, a[2*n+2], ' ', '-');
for (i = 1; i < 2 * n + 2; i++)
{
if (i != n + 1)
{
row1(n, a[i], '|', ' ');
}
}
}
}
int main()
{
int i, j, n;
char s[10];
while (scanf("%d%s", &n, &s), n || strcmp(s, "0") != 0)
{
for (i = 0; s[i] != 0; i++)
{
set(s[i] - '0', n, map[i]);
}
for (i = 0; i <= 2 * n + 2; i++)
{
for (j = 0; s[j] != 0; j++)
{
printf("%s ", map[j][i]);
}
printf("\n");
}
printf("\n");
}
}