LC-Display
来源:互联网 发布:济南程序员工资 编辑:程序博客网 时间:2024/04/18 15:33
110104 LCD 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 le 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 speci ed in the input le 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 ll 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 nd an example of each digit in the sample output
below.
Sample Input
2 12345
3 67890
0 0
Sample Output
-- -- --
| | | | | |
| | | | | |
-- -- -- --
| | | | |
| | | | |
-- -- --
--- --- --- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
个人测试无误,但是提交的时候出现了WA,暂时还没想到哪里出现错误了,不过系统说这道题是没有确切答案的,可能是对的。
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 le 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 speci ed in the input le 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 ll 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 nd an example of each digit in the sample output
below.
Sample Input
2 12345
3 67890
0 0
Sample Output
-- -- --
| | | | | |
| | | | | |
-- -- -- --
| | | | |
| | | | |
-- -- --
--- --- --- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- --- ---
思路:创建一个0-9的size 为1的一个数组,然后根据size的大少进行扩大,若用C来写,需要用一个二维的指针数组。
代码:
#include <stdio.h>#define MAXLENGTH 8void display(long size,long number){ int digits[MAXLENGTH],i,j; for(i = 0;i < MAXLENGTH;i++) digits[i] = -1; if(number == 0) digits[MAXLENGTH-1] = 0; else { for(i = MAXLENGTH-1;number >0;i--){ digits[i] = number % 10; number /= 10; } } char *outline[5][10]={ " - ", " ", " - ", " - ", " ", " - ", " - ", " - ", " - ", " - ", "| |", " |", " |", " |", "| |", "| ", "| ", " |", "| |", "| |", " ", " ", " - ", " - ", " - ", " - ", " - ", " ", " - ", " - ", "| |", " |", "| ", " |", " |", " |", "| |", " |", "| |", " |", " - ", " ", " - ", " - ", " ", " - ", " - ", " ", " - ", " - " }; int row; char *n; for(row = 1;row <= (2*size+3);row++){ for(i = 0;i < MAXLENGTH;i++) if(digits[i] != -1){ if(row ==1 ) n = outline[0][digits[i]]; if(2 <= row && row < (size + 2)) n = outline[1][digits[i]]; if(row == (size + 2)) n = outline[2][digits[i]]; if ((size + 3) <= row && row <= (2 * size + 2)) n = outline[3][digits[i]]; //对列处理 if (row == (2 * size + 3)) n = outline[4][digits[i]]; //对行处理 printf("%c",*n); for (j = 0; j < size; j++) printf("%c",*(n+1)); printf("%c",*(n+2)); printf(" "); } printf("\n"); }}int main(){ long size,number; while(scanf("%d %d",&size,&number) && (size != 0 && number >= 0)) display(size,number); return 0; }
个人测试无误,但是提交的时候出现了WA,暂时还没想到哪里出现错误了,不过系统说这道题是没有确切答案的,可能是对的。
- LC-Display
- LC-Display
- LC-Display
- LC-Display
- LC-Display
- LC-Display
- LC-Display
- LC-Display
- LC-Display(ZJU_1146)
- POJ 1102 LC DISPLAY
- poj 1102 LC-Display
- LC-Display(UVa706)
- poj1102 LC-Display
- HDU 1332 LC-Display
- uva706 LC-Display
- LC-Display POJ1102
- poj1102 LC-Display
- POJ 1102 LC-Display
- 链表逆序
- 提高flash的使用寿命技巧
- 09-12小结
- 初学spring mvc
- jsp dome
- LC-Display
- pthread_cond_t条件变量
- PV、EV、AC、BAC、EAC、ETC等计算公式含义
- Ubuntu Grub Rescue 解决Windows分区导致Ubuntu 12.10无法启动的问题
- UVa:907 Winterim Backpacking Trip
- Java7中的switch支持String的实现细节
- mysql反向解析导致连接数据库过慢的问题
- javascript 学习笔记
- qt添加so库时出现不可兼容错误