POJ 1102 LC-Display 模拟

Description

A friend of you has just bought a new computer. Until now, the most powerful computer he ever used has been a pocket calculator. Now, looking at his new computer, he is a bit disappointed, because he liked the LC-display of his
calculator so much. So you decide to write a program that displays numbers in an LC-display-like style on his computer.

Input

The input contains several lines, one for each number to be displayed. Each line contains two integers s, n (1 <= s <= 10, 0 <= n <= 99 999 999), where n is the number to be displayed and s is the size in which it shall be displayed.

The input file will be terminated by a line containing two zeros. This line should not be processed.

Output

Output the numbers given in the input file in an LC-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, also for the last digit.) There has to be exactly one column of blanks between two digits.

Output a blank line after each number. (You will find a sample of each digit in the sample output.)

Sample Input

2 12345
3 67890
0 0

Sample Output

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

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

输入的两个数分别是数字的尺寸 和要显示的数字组合  (注意:每两组数据空一行,每两个数字空一格)
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    char e[20][3]= {" -","-"};
    char q[33];
    char w[1][2]= {"|"};
    int m;
    int i,j,k;
    int t=0;
    while(scanf("%d%s",&m,q)!=EOF)
    {
        if(m==0)
            continue;
        if(t!=0)
            cout<<endl;
        t++;
        if(m==0&&q[0]=='0')
            break;
        for(i=0; i<=strlen(q)-1; i++)
        {
            if(i!=0)
                cout<<' ';
            if(q[i]=='1'||q[i]=='4')
            {
                for(j=1; j<=m+2; j++)
                    cout<<' ';
            }
            else
            {
                cout<<' ';
                for(j=1; j<=m; j++)
                {
                    cout<<e[1];
                }
                cout<<' ';
            }
        }
        cout<<endl;
        for(i=1; i<=m; i++)
        {
            for(k=0; k<=strlen(q)-1; k++)
            {
                if(k!=0)
                    cout<<' ';
                if(q[k]=='5'||q[k]=='6')
                {
                    cout<<w[0];
                    for(j=0; j<=m; j++)
                        cout<<' ';
                }
                else if(q[k]=='1'||q[k]=='2'||q[k]=='3'||q[k]=='7')
                {

                    for(j=0; j<=m; j++)
                        cout<<' ';
                    cout<<w[0];
                }
                else
                {
                    cout<<w[0];
                    for(j=0; j<m; j++)
                        cout<<' ';
                    cout<<w[0];
                }
            }
            cout<<endl;
        }
        for(i=0; i<strlen(q); i++)
        {
            if(i!=0)
                cout<<' ';
            if(q[i]=='1'||q[i]=='7'||q[i]=='0')
            {
                for(j=1; j<=m+2; j++)
                    cout<<' ';
            }
            else
            {
                cout<<' ';
                for(j=1; j<=m; j++)
                {
                    cout<<e[1];
                }
                cout<<' ';
            }
        }
        cout<<endl;
        for(i=1; i<=m; i++)
        {
            for(k=0; k<=strlen(q)-1; k++)
            {
                if(k!=0)
                    cout<<' ';
                if(q[k]=='2')
                {
                    cout<<w[0];
                    for(j=0; j<=m; j++)
                        cout<<' ';
                }
                else if(q[k]=='0'||q[k]=='8'||q[k]=='6')
                {
                    cout<<w[0];
                    for(j=0; j<m; j++)
                        cout<<' ';
                    cout<<w[0];
                }
                else
                {
                    for(j=0; j<=m; j++)
                        cout<<' ';
                    cout<<w[0];
                }
            }
            cout<<endl;
        }
        for(i=0; i<strlen(q); i++)
        {
            if(i!=0)
                cout<<' ';
            if(q[i]=='1'||q[i]=='7'||q[i]=='4')
            {
                for(j=1; j<=m+2; j++)
                    cout<<' ';
            }
            else
            {
                cout<<' ';
                for(j=1; j<=m; j++)
                {
                    cout<<e[1];
                }
                cout<<' ';
            }
        }
        cout<<endl;
    }
    return 0;
}

把没组数字分为五段 (三横二竖) 其实写出前两段 后三段也差不多了。。。
这次终于把速度提高了一点= =
显示出来的数字还挺 好看的 哈

POJ 1102 LC-Display 模拟

时间: 2024-11-06 15:35:31

POJ 1102 LC-Display 模拟的相关文章

poj 3399 Product(模拟)

# include <stdio.h> # include <string.h> # include <algorithm> using namespace std; int cmp(int x,int y) { return x>y; } int main() { int a[110],a1[110],a2[110],ans[110]; int n,k,k1,k2,i,k3; while(~scanf("%d%d",&n,&k

poj 2632 Crashing Robots, 模拟

点击打开链接 简单 模拟机器人的移动,发生碰撞时输出相应的信息. code #include <cstdio> #include <cstring> using namespace std; struct node{ int k; int s; } mtx[200][200]; struct node1{ int x, y; } rob[200]; int n, m; int dir[4][2]= {{0,1},{1,0},{0,-1},{-1,0}}; //N, E, S, W

【POJ】 Instant Complexity (模拟)

[POJ] Instant Complexity (模拟) Instant Complexity Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1905   Accepted: 657 Description Analyzing the run-time complexity of algorithms is an important tool for designing efficient programs that

POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)

题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道稍微恶心点的模拟,但毕竟是模拟,一般模拟都是只要示例过了基本就AC了,但这个题很特殊 我开始的时候一直跑不出测试示例,才发现题目中的插图和我构想的坐标系是不一样的(看来还不能轻易忽视掉插图啊) 这个题给出的坐标系是纵轴为y,横轴为x,y从下到上依次递增,x轴是从左到右递增 而我用的二维数组记录的地图,也就是说我的纵

POJ 3030. Nasty Hacks 模拟水题

Nasty Hacks Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13136   Accepted: 9077 Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of malicious software which teenagers may use to fool their friends.

poj 1102.LC-Display 解题报告

题目链接:http://poj.org/problem?id=1102 题目意思:就是根据给出的格式 s 和 数字 n,输出数值 n 的 LCD 显示.数值 n 的每个数字要占据 s + 2 列 和 2s + 3 行.数字和数字之间要有一个空格.数值与数值之间有一个空行. 首先对于LCD 的 7 个笔画显示编上序号 然后对于数字 i,分析出占用了哪几个笔画,例如,数字 1 占有的笔画是 3 和 6:数字 6 占有的笔画是 1, 2, 4, 5, 6, 7 用数组来存储每一个笔画分别被那些数字占有

HDU 1361 &amp; POJ 1068 Parencodings(模拟)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1361 POJ:http://poj.org/problem?id=1068 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn where

POJ 3295 Tautology (栈模拟)

Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10096   Accepted: 3847 Description WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some subset of the possible symbols K, A, N, C, E, p, q, r, s

POJ 1068 Parencodings (模拟),暑假第一题~

终于考完高线大,头也不那么疼了,也终于有空来刷题了~,先来一发水题试试水 题目链接:http://poj.org/problem?id=1068 简单的模拟,麻烦在理解题意,,英语好的请无视这句: [分析] S (((()()()))) P-sequence 4 5 6666 W-sequence 1 1 1456 如这个 S字符串, 题目给你一串数 4 5 6 6 6 6    对应P1 P2,,,Pn 意思是,第n个右括号')'左边有Pn 个左括号 ,,例如 456666 第1个右括号")&