2745:显示器
总时间限制: 1000ms 内存限制: 65536kB
描述
你的一个朋友买了一台电脑。他以前只用过计算器,因为电脑的显示器上显示的数字的样子和计算器是不一样,所以当他使用电脑的时候会比较郁闷。为了帮助他,你决定写一个程序把在电脑上的数字显示得像计算器上一样。
输入
输入包括若干行,每行表示一个要显示的数。每行有两个整数s和n (1 <= s <= 10, 0 <= n <= 99999999),这里n是要显示的数,s是要显示的数的尺寸。
如果某行输入包括两个0,表示输入结束。这行不需要处理。
输出
显示的方式是:用s个’-‘表示一个水平线段,用s个’|'表示一个垂直线段。这种情况下,每一个数字需要占用s+2列和2s+3行。另外,在两个数字之间要输出一个空白的列。在输出完每一个数之后,输出一个空白的行。注意:输出中空白的地方都要用空格来填充。
样例输入
2 12345
3 67890
0 0
样例输出
– – –
| | | | | |
| | | | | |
– – – –
| | | | |
| | | | |
– – –
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
提示
数字(digit)指的是0,或者1,或者2……或者9。
数(number)由一个或者多个数字组成。
问题链接:Bailian2745 显示器
问题描述:(略)
问题分析:
这个问题与参考链接是同一个问题,不解释。
程序说明:(略)
参考链接:UVALive5642 UVa706 HDU1332 POJ1102 LC-Display
题记:(略)
AC的C语言程序如下:
/* UVALive5642 UVa706 HDU1332 POJ1102 LC-Display */
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
string typematrix[10][5] = {
{
" - ",
"| |",
" ",
"| |",
" - "
},
{
" ",
" |",
" ",
" |",
" "
},
{
" - ",
" |",
" - ",
"| ",
" - "
},
{
" - ",
" |",
" - ",
" |",
" - "
},
{
" ",
"| |",
" - ",
" |",
" "
},
{
" - ",
"| ",
" - ",
" |",
" - "
},
{
" - ",
"| ",
" - ",
"| |",
" - "
},
{
" - ",
" |",
" ",
" |",
" "
},
{
" - ",
"| |",
" - ",
"| |",
" - "
},
{
" - ",
"| |",
" - ",
" |",
" - "
}
};
int getrow(int row, int multiple)
{
if(row == 0)
return 0; // 第1行
else if(row < multiple + 1)
return 1; // 第2行
else if(row == multiple + 1)
return 2; // 第3行
else if(row == 2 * multiple + 2)
return 4; // 第5行
else
return 3; // 第4行
}
void zoom(string& s, int n)
{
printf("%c",s[0]);
for(int i=0; i<n; i++) {
printf("%c", s[1]);
}
printf("%c", s[2]);
}
int main()
{
int n;
char s[100];
while(scanf("%d%s", &n, s) != EOF && n) {
for(int i=0; i<2*n+3; i++) { // 行控制
for(int j=0; j<(int)strlen(s); j++) { // 列控制
if(j != 0)
printf(" ");
zoom(typematrix[s[j] - '0'][getrow(i, n)], n);
}
printf("\n");
}
printf("\n");
}
return 0;
}