Notice
Recent Posts
Recent Comments
-
[SWEA_모의SW역량테스트] 5658번 - 보물상자 비밀번호 본문
https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRUN9KfZ8DFAUo
SWEA 5658번 모의기출문제다.
면이 4개인 정사각형에 숫자들이 적혀있고 이들이 회전하면서 생성가능한 숫자들의 조합을 확인해 요구조건에 맞는 답을 출력하는 문제다. 유형은 시뮬레이션.
특별한 규칙이라고할 건 없지만 temp와 상자정보를 유지하면서 돌려준 뒤 각 면에 있는 문자로 된 숫자들을 넣어두고 다 돌리면 내림 차순으로 정렬해서 [K-1] 번째 요소를 출력하면 된다.
아래는 소스코드.
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
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;
vector<long long> numbers; // 각 테스트 케이스에서 존재가능한 숫자들 저장.
int N, K, T;
string cur_num;
int answer_cnt = 1;
void store_num(vector<vector<char> >& box){
// numbers에 각 면의 숫자들 입력.
for (int r = 0; r < 4; r++){
long long sum = 0;
int sung = 0;
for (int c = N/4-1; c >=0; c--){
switch (box[r][c]){
case '1':
sum += 1 * pow(16, sung);
break;
case '2':
sum += 2 * pow(16, sung);
break;
case '3':
sum += 3 * pow(16, sung);
break;
case '4':
sum += 4 * pow(16, sung);
break;
case '5':
sum += 5 * pow(16, sung);
break;
case '6':
sum += 6 * pow(16, sung);
break;
case '7':
sum += 7 * pow(16, sung);
break;
case '8':
sum += 8 * pow(16, sung);
break;
case '9':
sum += 9 * pow(16, sung);
break;
case 'A':
sum += 10 * pow(16, sung);
break;
case 'B':
sum += 11 * pow(16, sung);
break;
case 'C':
sum += 12 * pow(16, sung);
break;
case 'D':
sum += 13 * pow(16, sung);
break;
case 'E':
sum += 14 * pow(16, sung);
break;
case 'F':
sum += 15 * pow(16, sung);
break;
}
sung++;
}
numbers.push_back(sum);
}
}
void move(vector<vector<char> >& box, vector<vector<char> >& temp){
// 한 칸씩 이동.
for (int r = 0; r < 4; r++){
for (int c = 1; c < (N / 4); c++){
box[r][c] = temp[r][c - 1];
}
}
box[0][0] = temp[3][(N / 4) - 1];
for (int r = 1; r < 4; r++){
box[r][0] = temp[r - 1][(N / 4) - 1];
}
// 이동 완료.
// temp에 복사.
for (int r = 0; r < 4; r++){
for (int c = 0; c < (N / 4); c++){
temp[r][c] = box[r][c];
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> T;
for (int i = 0; i < T; i++){
cin >> N >> K;
vector<vector<char> > box, temp;
cin >> cur_num;
box[j / (N / 4)][j % (N / 4)] = cur_num[j];
temp[j / (N / 4)][j % (N / 4)] = cur_num[j];
}
// 입력 완료.
for (int rotat = 0; rotat < (N / 4); rotat++){
if (rotat == 0){
store_num(box);
}
else{
move(box, temp);
store_num(box);
}
}
sort(numbers.begin(), numbers.end(), greater<long long>()); // 내림차순.
//for (int i = 0; i < numbers.size(); i++) cout << numbers[i] << " ";
cout << "#" << answer_cnt << " " << numbers[K - 1] << '\n';
answer_cnt++;
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'1-2. SWEA' 카테고리의 다른 글
[SWEA_모의SW역량테스트] 5644번 - 무선충전 (0) | 2020.01.27 |
---|---|
[SWEA_모의SW역량테스트] 5648번 - 원자 소멸 시뮬레이션 (0) | 2020.01.25 |
[SWEA_모의SW테스트] 5650번 - 핀볼 게임 (0) | 2020.01.23 |
[SWEA_모의SW역량테스트] 5653번 - 줄기세포 배양 (0) | 2020.01.22 |
[SWEA_모의SW역량테스트] 5656번 - 벽돌 깨기 (0) | 2020.01.21 |
Comments