ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [백준]2290 - LCD Test (구현)
    코테/백준 2023. 6. 19. 12:17

    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

    주어진 숫자를 그림과 같이 출력하는 문제

    https://astrid-dm.tistory.com/372

     

    도저히 감이 안와서 다른 블로그 글을 참조

    위 그림과 같이 7구역으로 나누고 각 숫자가 지나가는 구역을 배열로 표시한다

     

    #define _CRT_SECURE_NO_WARNINGS
    #include <string>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    int temp[10][7] = {
        {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
    };
    
    int main() {
        int N,k;
        cin >> N;
        cin >> k;
        vector<int> v;
        while (1) {
            int t;
            t = k % 10;
            v.push_back(t);
            k = k / 10;
            if (k == 0)
                break;
    
        }
        reverse(v.begin(), v.end());
    
        for (int i = 0; i < v.size(); i++) {
            if (temp[v[i]][0] == 0)
                for(int j=0 ; j<N+3 ; j++)
                    cout << ' ';
            else {
                cout << ' ';
                for (int j = 0; j < N; j++)
                    cout << '-';
                cout << ' ';
                cout << ' ';
            }
        }
        cout << '\n';
    
        for (int k = 0; k < N; k++) {
            for (int i = 0; i < v.size(); i++) {
                if (temp[v[i]][1] == 0 && temp[v[i]][2] == 0)
                    for (int j = 0; j < N + 3; j++)
                        cout << ' ';
                else if (temp[v[i]][1] == 1 && temp[v[i]][2] == 0) {
                    cout << '|';
                    for (int j = 0; j < N + 2; j++)
                        cout << ' ';
                }
                else if (temp[v[i]][2] == 1 && temp[v[i]][1] == 0) {
                    for (int j = 0; j < N + 1; j++)
                        cout << ' ';
                    cout << '|';
                    cout << ' ';
                }
                else {
                    cout << '|';
                    for (int j = 0; j < N; j++)
                        cout << ' ';
                    cout << '|';
                    cout << ' ';
                }
            }
            cout << '\n';
        }
    
        for (int i = 0; i < v.size(); i++) {
            if (temp[v[i]][3] == 0)
                for (int j = 0; j < N + 3; j++)
                    cout << ' ';
            else {
                cout << ' ';
                for (int j = 0; j < N; j++)
                    cout << '-';
                cout << ' ';
                cout << ' ';
            }
        }
        cout << '\n';
    
        for (int k = 0; k < N; k++) {
            for (int i = 0; i < v.size(); i++) {
                if (temp[v[i]][4] == 0 && temp[v[i]][5] == 0)
                    for (int j = 0; j < N + 3; j++)
                        cout << ' ';
                else if (temp[v[i]][4] == 1 && temp[v[i]][5] == 0) {
                    cout << '|';
                    for (int j = 0; j < N + 2; j++)
                        cout << ' ';
                }
                else if (temp[v[i]][5] == 1 && temp[v[i]][4] == 0) {
                    for (int j = 0; j < N + 1; j++)
                        cout << ' ';
                    cout << '|';
                    cout << ' ';
                }
                else {
                    cout << '|';
                    for (int j = 0; j < N; j++)
                        cout << ' ';
                    cout << '|';
                    cout << ' ';
                }
            }
            cout << '\n';
        }
    
        for (int i = 0; i < v.size(); i++) {
            if (temp[v[i]][6] == 0)
                for (int j = 0; j < N + 3; j++)
                    cout << ' ';
            else {
                cout << ' ';
                for (int j = 0; j < N; j++)
                    cout << '-';
                cout << ' ';
                cout << ' ';
            }
        }
    }

    이후엔 0번, 12번, 3번, 45번, 6번 구역을 값에 따라 출력해주면 끝

    '코테 > 백준' 카테고리의 다른 글

    [백준]2252 - 줄세우기 (DFS + 위상정렬)  (0) 2023.06.22
    [백준]6987 - 월드컵 (백트래킹)  (0) 2023.06.19
    [백준]16506 - CPU  (0) 2023.06.19
    [백준]3568 - iSharp (구현)  (0) 2023.06.19
    [백준]14500 - 테르로미노  (0) 2023.03.02
Designed by Tistory.