알고리즘

백준 2290번 LCD Test (JAVA)

박카스마시며코딩 2023. 12. 20. 23:08

https://www.acmicpc.net/problem/2290

 

2290번: LCD Test

첫째 줄에 두 개의 정수 s와 n이 들어온다. (1 ≤ s ≤ 10, 0 ≤ n ≤ 9,999,999,999)이다. n은 LCD 모니터에 나타내야 할 수 이며, s는 크기이다.

www.acmicpc.net

 

저는 구현을 통해 문제를 풀었습니다.

 

 

package BOJ.simulation;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class BOJ_2290 {

    private static final char[][][] NUMBER = new char[][][] {
        { // 0
            {' ','-',' '},
            {'|',' ','|'},
            {' ',' ',' '},
            {'|',' ','|'},
            {' ','-',' '}
        },
        { // 1
            {' ',' ',' '},
            {' ',' ','|'},
            {' ',' ',' '},
            {' ',' ','|'},
            {' ',' ',' '}
        },
        { // 2
            {' ','-',' '},
            {' ',' ','|'},
            {' ','-',' '},
            {'|',' ',' '},
            {' ','-',' '}
        },
        { // 3
            {' ','-',' '},
            {' ',' ','|'},
            {' ','-',' '},
            {' ',' ','|'},
            {' ','-',' '}
        },
        { // 4
            {' ',' ',' '},
            {'|',' ','|'},
            {' ','-',' '},
            {' ',' ','|'},
            {' ',' ',' '}
        },
        { // 5
            {' ','-',' '},
            {'|',' ',' '},
            {' ','-',' '},
            {' ',' ','|'},
            {' ','-',' '}
        },
        { // 6
            {' ','-',' '},
            {'|',' ',' '},
            {' ','-',' '},
            {'|',' ','|'},
            {' ','-',' '}
        },
        { // 7
            {' ','-',' '},
            {' ',' ','|'},
            {' ',' ',' '},
            {' ',' ','|'},
            {' ',' ',' '}
        },
        { // 8
            {' ','-',' '},
            {'|',' ','|'},
            {' ','-',' '},
            {'|',' ','|'},
            {' ','-',' '}
        },
        { // 9
            {' ','-',' '},
            {'|',' ','|'},
            {' ','-',' '},
            {' ',' ','|'},
            {' ','-',' '}
        },
    };

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int s = Integer.parseInt(st.nextToken());
        String number = st.nextToken();
        makeLCD(number,s);
    }

    private static void makeLCD(String number, int s) {
        int n = 5;
        StringBuilder[] result = new StringBuilder[n];
        for(int i = 0  ; i < n ; i++){
            result[i] = new StringBuilder();
        }
        int index = 0;
        for(int i = 0 ; i < number.length() ; i++){
            int now = number.charAt(i) - '0';
            fillResult(result,now,s,n);
        }
        for(int i = 0  ; i < n ; i++){
            if(i == 1 || i == 3){
                for(int j = 0 ; j < s; j++){
                    System.out.println(result[i]);
                }
                continue;
            }
            System.out.println(result[i]);
        }
    }

    private static void fillResult(StringBuilder[] result, int now, int s, int n) {
        for(int i = 0 ; i < 5 ; i++){
            for(int j = 0 ; j < 3 ; j++){
                result[i].append(NUMBER[now][i][j]);
                if(j == 1){ // 중간 것은 개수만큼 추가
                    for(int k = 0 ; k < s - 1; k++){
                        result[i].append(NUMBER[now][i][j]);
                    }
                }
            }
        }
        for(int i = 0 ; i < 5 ; i++){
            result[i].append(' ');
        }
    }


}

'알고리즘' 카테고리의 다른 글

백준 21756번 지우개 (JAVA)  (0) 2023.12.22
백준 12761번 돌다리 (JAVA)  (1) 2023.12.21
백준 9655번 돌 게임 (JAVA)  (0) 2023.12.19
백준 11047번 동전 0 (JAVA)  (0) 2023.12.18
백준 16113번 시그널 (JAVA)  (0) 2023.12.17