PKU 1102 LC-Display (有趣的模拟)
LC-Display
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10720 | Accepted: 4221 |
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.
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.)
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
Mid-Central European Regional Contest 1999
思路:
这题,不会...
无奈看其他人代码,发现居然可以写的这么简洁...佩服...
代码:
这题,不会...
无奈看其他人代码,发现居然可以写的这么简洁...佩服...
代码:
1
#include
<
stdio.h
>
2 #include < stdlib.h >
3 #include < string .h >
4 #define MAX_LEN 10
5 int n;
6 char str[MAX_LEN];
7 const int mark[ 5 ][ 10 ][ 3 ] = {
8 /* 0 1 2 3 4 5 6 7 8 9 */
9 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 ,
10 1 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 ,
11 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 ,
12 1 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 1 ,
13 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 };
14
15 int
16 main( int argc, char ** argv)
17 {
18 int j, k, p, q, w;
19 while (scanf( " %d %s " , & n, str) != EOF) {
20 if ( ! n)
21 break ;
22 for (j = 0 ; j < 5 ; j ++ ) {
23 if (j % 2 == 0 ) {
24 for (p = 0 ; str[p] != ' \0 ' ; p ++ ) {
25 printf( " " ); /* mark[j][k][0] */
26 k = str[p] - ' 0 ' ;
27 for (q = 0 ; q < n; q ++ )
28 printf( " %s " , mark[j][k][ 1 ] ? " - " : " " );
29 printf( " " ); /* mark[j][k][2] */
30 printf( " " );
31 }
32 printf( " \n " );
33 } else {
34 for (q = 0 ; q < n; q ++ ) {
35 for (p = 0 ; str[p] != ' \0 ' ; p ++ ) {
36 k = str[p] - ' 0 ' ;
37 printf( " %s " , mark[j][k][ 0 ] ? " | " : " " );
38 for (w = 0 ; w < n; w ++ )
39 printf( " " );
40 printf( " %s " , mark[j][k][ 2 ] ? " | " : " " );
41 printf( " " );
42 }
43 printf( " \n " );
44 }
45 }
46 }
47 printf( " \n " );
48 }
49 return 0 ;
50 }
2 #include < stdlib.h >
3 #include < string .h >
4 #define MAX_LEN 10
5 int n;
6 char str[MAX_LEN];
7 const int mark[ 5 ][ 10 ][ 3 ] = {
8 /* 0 1 2 3 4 5 6 7 8 9 */
9 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 ,
10 1 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 ,
11 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 ,
12 1 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 1 ,
13 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 };
14
15 int
16 main( int argc, char ** argv)
17 {
18 int j, k, p, q, w;
19 while (scanf( " %d %s " , & n, str) != EOF) {
20 if ( ! n)
21 break ;
22 for (j = 0 ; j < 5 ; j ++ ) {
23 if (j % 2 == 0 ) {
24 for (p = 0 ; str[p] != ' \0 ' ; p ++ ) {
25 printf( " " ); /* mark[j][k][0] */
26 k = str[p] - ' 0 ' ;
27 for (q = 0 ; q < n; q ++ )
28 printf( " %s " , mark[j][k][ 1 ] ? " - " : " " );
29 printf( " " ); /* mark[j][k][2] */
30 printf( " " );
31 }
32 printf( " \n " );
33 } else {
34 for (q = 0 ; q < n; q ++ ) {
35 for (p = 0 ; str[p] != ' \0 ' ; p ++ ) {
36 k = str[p] - ' 0 ' ;
37 printf( " %s " , mark[j][k][ 0 ] ? " | " : " " );
38 for (w = 0 ; w < n; w ++ )
39 printf( " " );
40 printf( " %s " , mark[j][k][ 2 ] ? " | " : " " );
41 printf( " " );
42 }
43 printf( " \n " );
44 }
45 }
46 }
47 printf( " \n " );
48 }
49 return 0 ;
50 }