Brian Warehouse

Some birds aren`t meant to be caged, their feathers are just too bright... ...
posts - 40, comments - 16, trackbacks - 0, articles - 1

POJ Grids 2745 显示器

Posted on 2010-08-17 14:17 Brian 阅读(433) 评论(0)  编辑 收藏 引用 所属分类: POJ

Description

你的一个朋友买了一台电脑。他以前只用过计算器,因为电脑的显示器上显示的数字的样子和计算器是不一样,所以当他使用电脑的时候会比较郁闷。为了帮助他,你决定写一个程序把在电脑上的数字显示得像计算器上一样。

Input

输入包括若干行,每行表示一个要显示的数。每行有两个整数s和n (1 <= s <= 10, 0 <= n <= 99999999),这里n是要显示的数,s是要显示的数的尺寸。

如果某行输入包括两个0,表示输入结束。这行不需要处理。

Output

显示的方式是:用s个'-'表示一个水平线段,用s个'|'表示一个垂直线段。这种情况下,每一个数字需要占用s+2列和2s+3行。另外,在两个数字之间要输出一个空白的列。在输出完每一个数之后,输出一个空白的行。注意:输出中空白的地方都要用空格来填充。

Sample Input

2 12345
3 67890
0 0

 

 

Sample Output

      --   --        --
|    |    | |  | |
|    |    | |  | |
--   --   --   --
| |       |    |    |
| |       |    |    |
--   --        --
---   ---   ---   ---   ---
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
---         ---   ---
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
---         ---   ---   ---

 

 

Hint

数字(digit)指的是0,或者1,或者2……或者9。
数(number)由一个或者多个数字组成。

这题横跨我一个学期之久,后来无奈还是百度了一下:

#include <iostream>
using namespace std;

char n1[] = "- -- -----";
char n2[] = "|   ||| ||";
char n3[] = "|||||  |||";
char n4[] = "  ----- --";
char n5[] = "| |   | | ";
char n6[] = "|| |||||||";
char n7[] = "- -- -- --";

int main()
{
    
int m;
    
char n[10];
    cin
>>m>>n;
    
while ((n[0]-'0')||m)
    {
        
int len = strlen(n);
        
for (int i=0;i<len;i++)
        {
            cout
<<" ";
            
int num = n[i]-'0';
            
for (int j=0;j<m;j++)
            {
                cout
<<n1[num];
            }
            cout
<<"  ";
        }
        cout
<<endl;
        
int temp = m;
        
while (temp--)
        {
            
for (int i=0;i<len;i++)
            {
                
int num = n[i]-'0';
                cout
<<n2[num];
                
for (int j=0;j<m;j++)
                {
                    cout
<<" ";
                }
                cout
<<n3[num];
                cout
<<" ";
            }
            cout
<<endl;
        }
        
for (int i=0;i<len;i++)
        {
            cout
<<" ";
            
int num = n[i]-'0';
            
for (int j=0;j<m;j++)
            {
                cout
<<n4[num];
            }
            cout
<<"  ";
        }
        cout
<<endl;
        temp 
= m;
        
while (temp--)
        {
            
for (int i=0;i<len;i++)
            {
                
int num = n[i]-'0';
                cout
<<n5[num];
                
for (int j=0;j<m;j++)
                {
                    cout
<<" ";
                }
                cout
<<n6[num];
                cout
<<" ";
            }
            cout
<<endl;
        }
        
for (int i=0;i<len;i++)
        {
            cout
<<" ";
            
int num = n[i]-'0';
            
for (int j=0;j<m;j++)
            {
                cout
<<n7[num];
            }
            cout
<<"  ";
        }
        cout
<<endl<<endl;

        cin
>>m>>n;
    }
    
return 0;
}

 

我想,第一次做出来这题的人真是了不起!


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理