24h購物| | PChome| 登入
2012-07-01 17:07:26| 人氣2,694| 回應0 | 上一篇 | 下一篇

[UVA] 706 - LC Display

推薦 0 收藏 0 轉貼0 訂閱站台


  LC-Display 

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 file contains several lines, one for each number to be displayed. Each line contains two integers s, n ( $1 le s le 10, 0
le n le 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 

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

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


總覺得 UVa 好像打成 LCD - Display


#include<stdio.h>
char type[5][6] = {
    {"    "},{"   |"},{"|   "},{"|  |"},{" -- "},
    };
char Num[10][5] = {
    {4,3,0,3,4},/*0*/
    {0,1,0,1,0},/*1*/
    {4,1,4,2,4},/*2*/
    {4,1,4,1,4},/*3*/
    {0,3,4,1,0},/*4*/
    {4,2,4,1,4},/*5*/
    {4,2,4,3,4},/*6*/
    {4,1,0,1,0},/*7*/
    {4,3,4,3,4},/*8*/
    {4,3,4,1,4}/*9*/
                    };
void PrintNum(char s[], int n) {
    int a, b, c, tn;
    for(a = 0; a < 5; a++) {
        if(a == 0 || a == 2 || a == 4) tn = 1;
        else tn = n;
        while(tn--) {
            for(b = 0; s[b]; b++) {
                if(s[b] == ' ') {putchar(' ');continue;}
                putchar(type[Num[s[b] - '0'][a]][0]);
                for(c = 0; c < n; c++)
                    putchar(type[Num[s[b] - '0'][a]][1]);
                putchar(type[Num[s[b] - '0'][a]][3]);
                if(s[b+1] != '\0') putchar(' ');
            }
            puts("");
        }
    }
}
main() {
    int n;
    char s[20];
    while(scanf("%d %s", &n, s) == 2) {
        if(n == 0)
            break;
        PrintNum(s, n);
        puts("");
    }
    return 0;
}


台長: Morris
人氣(2,694) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 400 - Unix ls
此分類上一篇:[UVA] 12027 - Very Big Perfect Squares

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文