반응형

문제 출처 :


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



알고리즘 분석 :


문제 해결에 필요한 사항

1. 구현


우선 입력을 받고 가로6 세로7짜리 입력의 숫자가 무엇인지 파악한다.


그리고 그 숫자들을 특정 string에 추가해주고 stoll로 숫자를 치환한 후 next_permutation을 통해 그다음 숫자를 파악한다.


그다음 숫자가 자신보다 작거나 같으면 The End이고 그 외에는 다시 문자열 그림으로 치환하여 출력한다.






소스 코드 : 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
 
using namespace std;
 
string number[10][10= {
    {
        "000000",
        "001100",
        "010010",
        "010010",
        "010010",
        "001100",
        "000000",
    },
    {
        "000000",
        "000100",
        "001100",
        "000100",
        "000100",
        "000100",
        "000000",
    },
    {
        "000000",
        "011110",
        "000010",
        "011110",
        "010000",
        "011110",
        "000000",
    },
    {
        "000000",
        "011100",
        "000010",
        "000100",
        "000010",
        "011100",
        "000000",
    },
    {
        "000000",
        "000100",
        "001100",
        "010100",
        "111110",
        "000100",
        "000000",
    },
    {
        "000000",
        "011110",
        "010000",
        "011100",
        "000010",
        "010010",
        "001100",
    },
    {
        "000000",
        "010000",
        "010000",
        "011110",
        "010010",
        "011110",
        "000000",
    },
    {
        "000000",
        "011110",
        "000010",
        "000100",
        "000100",
        "000100",
        "000000",
    },
    {
        "000000",
        "011110",
        "010010",
        "011110",
        "010010",
        "011110",
        "000000",
    },
    {
        "011110",
        "010010",
        "010010",
        "011110",
        "000010",
        "000010",
        "000010",
    }
};
 
int main() {
    string tmp[10];
 
    for (int i = 0; i < 7; i++)
        cin >> tmp[i];
 
    string num[10][10= { "", };
 
    int len = tmp[0].size(); 
    int cnt = tmp[0].size() / 6;
 
    for (int i = 0; i < 7; i++)
        for (int j = 0; j < len; j++) {
            num[j / 6][i] += tmp[i][j];
        }
 
    string cur = "";
    for (int i = 0; i < cnt; i++) {
        if (num[i][4== "010010") {
            if(num[i][1== "001100")
                cur += "0";
            else if (num[i][1== "010000")
                cur += "6";
            else
                cur += "8";
        }
        else if (num[i][4== "000100") {
            if(num[i][1== "000100")
                cur += "1";
            else 
                cur += "7";
        }
        else if (num[i][4== "010000")
            cur += "2";
        else if (num[i][4== "000010") {
            if(num[i][1== "011100")
                cur += "3";
            else if(num[i][1== "011110")
                cur += "5";
            else if (num[i][1== "010010")
                cur += "9";
        }
        else if (num[i][4== "111110")
            cur += "4";
    }
    
    string next = cur;
    next_permutation(next.begin(), next.end());
 
    if (stoll(cur) >= stoll(next)) {
        cout << "The End";
        return 0;
    }
 
    int ret = 0;
    for (int i = 0; i < 7; i++) {
        for (int j = 0; j < len; j++) {
            cout << number[next[j / 6- '0'][i][j % 6];
        }
        cout << endl;
    }
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형

'Applied > 알고리즘 문제풀이' 카테고리의 다른 글

[14890번] 경사로  (0) 2018.09.27
[1038번] 감소하는 수  (0) 2018.09.25
[15965번] K번째 소수  (0) 2018.09.21
[9882번] Balanced Teams  (0) 2018.09.21
[15927번] 회문은 회문아니야!!  (0) 2018.09.19