문제 4. LCD 디스플레이(LCD Display) (Question 4. LC-Display)

문제 4. LCD 디스플레이(LCD Display)

PC/UVa ID : 110104/706, 인기도 : A, 성공률 : 보통, 레벨 : 1

한 친구가 방금 새 컴퓨터를 샀다. 그 친구가 지금까지 샀던 가장 강력한 컴퓨터는 공학용 전자 계산기였다. 그런데 그 친구는 새 컴퓨터의 모니터보다 공학용 계산기에 있는 LCD 디스플레이가 더 좋다며 크게 실망하고 말았다.

그 친구를 만족시킬 수 있도록 숫자를 LCD 디스플레이 방식으로 출력하는 프로그램을 만들어 보자.

입력
입력 파일은 여러 줄로 구성되며 표시될 각각의 숫자마다 한 줄씩 입력된다. 각 줄에는 s와 n이라는 두 개의 정수가 들어있으며, n은 출력될 숫자(0 <= n <= 99,999,999), s는 숫자를 표시하는 크기(1 <= s <= 10)를 의미한다. 0이 두 개 입력된 줄이 있으면 입력이 종료되며 그 줄은 처리되지 않는다.

출력
입력 파일에서 지정한 숫자를 수평 방향은 '-' 기호를, 수직 방향은 '|'를 이용해서 LCD 디스플레이 형태로 출력한다. 각 숫자는 정확하게 s + 2 개의 열, 2s + 3개의 행으로 구성된다.

마지막 숫자를 포함한 모든 숫자를 이루는 공백을 스페이스로 채워야 한다. 두개의 숫자 사이에는 정확하게 한 열의 공백이 있어야 한다.

각 숫자 다음에는 빈 줄을 한 줄로 출력한다. 밑은 각 숫자를 출력하는 방식이 나와 있다.


A friend of yours has just bought a new computer. Before this, the most powerful machine he ever used was a pocket calculator. He is a little disappointed because he liked the LCD display of his calculator more than the screen on his new computer! To make him happy, write a program that prints numbers in LCD display style.

Input

The input file contains several lines, one for each number to be displayed. Each line contains integers s and n, where n is the number to be displayed ( 0$ \le$n$ \le$99, 999, 999) and s is the size in which it shall be displayed ( 1$ \le$s$ \le$10). The input will be terminated by a line containing two zeros, which should not be processed.

Output

Print the numbers specified in the input file in an LCD 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, including the last digit. There must be exactly one column of blanks between two digits.
Output a blank line after each number. You will find an example of each digit in the sample output below.

Sample Input

2 12345
3 67890
0 0

Sample Output



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

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






Anyone help me!!! I have no idea why my answer is wrong.
Please let me know what's wrong..

My answers

My answer type 1.
=======================================================================================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define PRINT_HOR(x) x?printf("-"):PRINT_SPACE // print horizon bar : '-' or space : ' '
#define PRINT_VER(x) x?printf("|"):PRINT_SPACE // print verical bar : '|' or space : ' '
#define PRINT_SPACE  printf(" ")     // print space : ' '
#define PRINT_LF  printf("\n")

int main(int argc, char argv[]){

 int i,j,tmp=0;
 int seq,pos;
 int horizon;
 char val[8];
 short single_num;
 
 /*=== my number seq ===
 ** A number is composited with seven part
  0 -
  1| |2
  3 -
  4| |5
  6 -
 */
 
 int num[][7]={  // number array
 {1,1,1,0,1,1,1}, // 0
 {0,0,1,0,0,1,0}, // 1
 {1,0,1,1,1,0,1}, // 2
 {1,0,1,1,0,1,1},  // 3
 {0,1,1,1,0,1,0}, // 4
 {1,1,0,1,0,1,1}, // 5
 {1,1,0,1,1,1,1}, // 6
 {1,0,1,0,0,1,0}, // 7
 {1,1,1,1,1,1,1}, // 8
 {1,1,1,1,0,1,1}}; // 9

 while(1){  

  //------------- get input ------------
  scanf("%d",&horizon);
  scanf("%s",&val);  
  
  
  
  if(horizon == 0 && val[0] == '0')
   break;
  //-----------End of get input --------
  
  //----------- Print number -----------
  for(pos=0; pos<7 ;pos++){ 
  
   // check for printing vertical bar
   // do nothing on 2, 5 part. 
   // Just Check it
   if(pos == 2 || pos == 5){
    // on 1, 4 part, I'm printing vertical bar.
    // so, decrease num 2 or 5 to 1 or 4
    // then loop as many as horizon
    ++tmp == horizon ? tmp=0, pos++ : pos-- ;
   }
  
   // loop as many as count of Numbers
   for(seq=0 ; val[seq] != '\0' ; seq++){
    
    single_num = val[seq]-48;
    
    // print horizon bar. part 0, 3, 6
    if(pos%3 ==0){ 
     if(single_num != 3 && single_num != 7)
      PRINT_SPACE;    // print ' '
     for(i=0; i<horizon ; i++) // print '-'
      PRINT_HOR( num[single_num][pos] );
     PRINT_SPACE;    // print ' '
    }
    
    // print vertical bar. part 1, 2, 4, 5
    else if(pos%3 == 1){   // print '|' and ' '
     if(single_num != 3 && single_num != 7)
      PRINT_VER( num[single_num][pos] ); // print '|' :part 1 or 4
     if( pos == 1 || pos == 4 ){   // print ' '
      for(j=0; j<horizon ; j++){
       PRINT_SPACE;
      }
     }
     PRINT_VER( num[single_num][pos+1] );// print '|' :part 2 or 5
    }
    PRINT_SPACE; // print gap of numbers
   }
   PRINT_LF;   // print new line
  }
  PRINT_LF;   // print new line
  //---------- End of Print number --------     
 }
 
 return 0;
}



My answer 2.
================================================================================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define PRINT_HOR(x) x?printf("-"):PRINT_SPACE // print horizon bar : '-' or space : ' '
#define PRINT_VER(x) x?printf("|"):PRINT_SPACE // print verical bar : '|' or space : ' '
#define PRINT_SPACE  printf(" ")     // print space : ' '
#define PRINT_LF  printf("\n")

int main(int argc, char argv[]){

 int i,j,tmp=0;
 int seq,pos;
 int horizon[100];
 char val[100][9];
 short single_num;
 int cmd_num, cnt;
 
 /*=== my number seq ===
 ** A number is composited with seven part
  0 -
  1| |2
  3 -
  4| |5
  6 -
 */
 
 int num[][7]={  // number array
 {1,1,1,0,1,1,1}, // 0
 {0,0,1,0,0,1,0}, // 1
 {1,0,1,1,1,0,1}, // 2
 {1,0,1,1,0,1,1},  // 3
 {0,1,1,1,0,1,0}, // 4
 {1,1,0,1,0,1,1}, // 5
 {1,1,0,1,1,1,1}, // 6
 {1,0,1,0,0,1,0}, // 7
 {1,1,1,1,1,1,1}, // 8
 {1,1,1,1,0,1,1}}; // 9

 //------------- get input ------------
 for(i=0;;i++){
 
  scanf("%d",&horizon[i]);
  scanf("%s",val[i]);
  
  val[i][9] = '\0';
  
  if(horizon[i] == 0 && val[i][0] == '0')
   break;
  
 }
 //-----------End of get input --------
  
  
 //----------- Print number -----------
 for(cnt = 0; horizon[cnt] > 0 ; cnt++){ 
 
  //-------- Loop as many as parts of number ----------
  for(pos=0; pos<7 ;pos++){ 
  
   // check for printing vertical bar
   // do nothing on 2, 5 part. 
   // Just Check it
   if(pos == 2 || pos == 5){
    // on 1, 4 part, I'm printing vertical bar.
    // so, decrease num 2 or 5 to 1 or 4
    // then loop as many as horizon
    ++tmp == horizon[cnt] ? tmp=0, pos++ : pos-- ;
   }
  
   // loop as many as count of Numbers
   for(seq=0 ; val[cnt][seq] != '\0' ; seq++){
    
    single_num = val[cnt][seq]-48;
    
    // print horizon bar. part 0, 3, 6
    if(pos%3 ==0){ 
     if(single_num != 3 && single_num != 7)
      PRINT_SPACE;    // print ' '
     for(i=0; i<horizon[cnt] ; i++) // print '-'
      PRINT_HOR( num[single_num][pos] );
     PRINT_SPACE;    // print ' '
    }
    
    // print vertical bar. part 1, 2, 4, 5
    else if(pos%3 == 1){   // print '|' and ' '
     if(single_num != 3 && single_num != 7)
      PRINT_VER( num[single_num][pos] ); // print '|' :part 1 or 4
     if( pos == 1 || pos == 4 ){   // print ' '
      for(j=0; j<horizon[cnt] ; j++){
       PRINT_SPACE;
      }
     }
     PRINT_VER( num[single_num][pos+1] );// print '|' :part 2 or 5
    }
    PRINT_SPACE; // print gap of numbers
   }
   PRINT_LF;   // print new line
  }  
  PRINT_LF;   // print new line
  //---------- End of Print number --------       
 }

 return 0;
}



댓글 없음:

댓글 쓰기

안녕하세요 :)