http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=110104&format=html

UVA 706_LC-Display(液晶显示屏)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=29&page=show_problem&problem=647

题目大意:

输入:s和n两个数,n为需要显示的数,s为显示的大小。当输入两个0时结束

输出:模拟液晶显示屏显示,用s个'-'表示水平线段,s个'|'表示竖直线段。

每个阿拉伯数字占用s+2列和2*s+3行,数字的空白之处要填上空格,

每两个数字之间要有一个空列。每个整数后面输出一个空行

 样例输入:

2 12345
3 67890
0 0
样例输出:
      --   --        -- 
   |    |    | |  | |   
   |    |    | |  | |   
      --   --   --   -- 
   | |       |    |    |
   | |       |    |    |
      --   --        -- 

 ---   ---   ---   ---   --- 
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
 ---         ---   ---       
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
 ---         ---   ---   ---
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;

int d[10];
//对0到9每个数字当s等于1的显示存入数组,当s扩大时,将对应数字笔画扩大
string line[5][10] = {
" - ", "", " - ", " - ", "", " - ", " - ", " - ", " - ", " - ",
"| |", " |", " |", " |", "| |", "| ", "| ", " |", "| |", "| |",
"", "", " - ", " - ", " - ", " - ", " - ", "", " - ", " - ",
"| |", " |", "| ", " |", " |", " |", "| |", " |", "| |", " |",
" - ", "", " - ", " - ", "", " - ", " - ", "", " - ", " - "
};
int main()
{
int s,n,i,j,k,t,m;
string str;
while(scanf("%d%d",&s,&n)!=EOF&&s||n)
{
m=0;
if(n==0)
{
m=1;
d[0]=0;
}
else
{
while(n)
{
d[m++]=n%10;
n/=10;
}
}
j=0;
for(t=0;t<2*s+3;t++)
{
for(i=m-1;i>=0;i--)
{
if(t==0)
str=line[0][d[i]];
if(t>=1&&t<=s)
str=line[1][d[i]];
if(t==s+1)
str=line[2][d[i]];
if(t>s+1&&t<=2*s+1)
str=line[3][d[i]];
if(t==2*s+2)
str=line[4][d[i]];

//每一笔由三个字符组成,两边输出一次,中间进行扩大
cout<<str[0];
for(k=1;k<=s;k++)
cout<<str[1];
cout<<str[2];
if(i>0) //两个数字之间有一列空格
cout<<" ";
}
cout<<endl;
}
cout<<endl;
}
return 0;
}



posted on 2012-02-29 10:59  pcoda  阅读(402)  评论(0编辑  收藏  举报