《挑戰編程》之液晶顯示器

 

最近在看老美的一本《挑戰編程》,感覺這書挺有意思的,只是沒有答案。做了幾道,可能是因爲開頭的幾道不算難吧,感覺還算順利。

 

題目如下,沒有翻譯,見諒哈

 

1.6.4 LCD Display


PC/UVa IDs: 110104/706, Popularity: A, Success rate: average Level: 1


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 12345
3 67890
0 0

 

Sample Output
……(顯示不出來,有點像搜狗的酷字,大家運行一下就知道了)

 

代碼如下:

 

 

代碼中的頭文件<Fatal.h>是我自己編寫的一個出錯處理,該頭文件是用宏定義的,打印用戶傳遞的字符串;

定義VER1和VER2是爲了使用兩個不同的版本,我覺得VER2更好。

不過我覺得,使用全局數組不算是很好的辦法,期待更好的辦法。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章