joj1025 LC-Display

1025: LC-Display


Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
3s 8192K 2251 642 Standard
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

      --   --        -- 

   |    |    | |  | |   

   |    |    | |  | |   

      --   --   --   -- 

   | |       |    |    |

   | |       |    |    |

      --   --        -- 



 ---   ---   ---   ---   --- 

|         | |   | |   | |   |

|         | |   | |   | |   |

|         | |   | |   | |   |

 ---         ---   ---       

|   |     | |   |     | |   |

|   |     | |   |     | |   |

|   |     | |   |     | |   |

 ---         ---   ---   --- 



 


Submit / Problem List / Status / Discuss

 

想了半天回,实在是没有能减少代码量的想法。我的想法是暴力模拟,直接把0-9全写出来,一个个处理。但是代码几百行几百行。

参考了大牛代码。

直接贴上,过些日子再想想。

 1 #include <iostream>
2 #include <string>
3
4 using namespace std;
5
6 char code[5][31]=
7 {
8 {" - - - - - - - - "},
9 {"| | | | || || | || || |"},
10 {" - - - - - - - "},
11 {"| | || | | || | || | |"},
12 {" - - - - - - - "},
13 };
14
15 void print(int n, string& s,int i)
16 {
17 int length = s.length();
18 int j, k, m;
19 for(j =0; j < length; j++)
20 {
21 /* 找到数字j的下标 */
22 m =(s[j]-'0')*3;
23
24 cout<< code[i][m];
25 /* 关键笔画打印n次 */
26 for(k =0; k < n; k++)
27 {
28 cout<< code[i][m +1];
29 }
30 cout<< code[i][m +2];
31
32 /* 每2个数字间加一个空格 */
33 if(j != length -1)cout<<" ";
34 }
35 cout<< endl;
36 }
37
38 int main()
39 {
40 int i, j, n;
41 string s;
42 while(1)
43 {
44 cin >> n;
45 if(n ==0)break;
46 cin >> s;
47 for(i =0; i <5; i++)
48 {
49 if(i %2)
50 {
51 /* 纵行要打印n次 */
52 for(j =0; j < n; j++)
53 {
54 print(n, s, i);
55 }
56 }
57 else
58 {
59 print(n, s, i);
60 }
61 }
62 cout<< endl;
63 }
64    //system("pause");
65 return0;
66 }
67



你可能感兴趣的:(display)