728x90
반응형

27495번: 만다라트 만들기
문제
https://www.acmicpc.net/problem/27495
27495번: 만다라트 만들기
1번째 줄에는 “#x. “를 출력한 다음, 사전순으로 가장 먼저 오는 중간 목표를 출력한다. 숫자가 알파벳보다 사전순으로 먼저 오고, 알파벳 대문자가 알파벳 소문자보다 사전순으로 먼저 온다. 2
www.acmicpc.net
풀이
배열에서 (1,1), (1,4), (1,7), (4,1), (4,7), (7,1), (7,4), (7,7) 8점의 좌표와 문자열을 문자열 사전순으로 정렬하고 좌표를 (x, y)라고 한다면 (x-1, y-1)부터 (x+1, y+1)까지 (x, y)를 제외한 값을 또다시 정렬해 차례대로 출력하면 된다. 출력 형식만 잘 지켜서 구현하면 된다.
코드
#include <bits/stdc++.h>
using namespace std;
vector<vector<string>> graph(9, vector<string>(9, ""));
int cnt = 1;
void func(int x, int y) {
cout << "#" << cnt << ". " << graph[x][y] << '\n';
vector<string> tmp;
for (int i = x - 1; i <= x + 1; i++)
for (int j = y - 1; j <= y + 1; j++)
if (i == x && j == y)
continue;
else
tmp.push_back(graph[i][j]);
sort(tmp.begin(), tmp.end());
for (int i = 0; i < 8; i++) {
cout << "#" << cnt << "-" << i + 1 << ". " << tmp[i] << '\n';
}
cnt++;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
cin >> graph[i][j];
int d[] = {1, 4, 7};
vector<pair<string, pair<int, int>>> v;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (i == 1 && j == 1)
continue;
else
v.push_back({graph[d[i]][d[j]], {d[i], d[j]}});
sort(v.begin(), v.end());
for (auto i : v) {
int x = i.second.first;
int y = i.second.second;
func(x, y);
}
return 0;
}
728x90
반응형
'Problem Solving > BOJ' 카테고리의 다른 글
[백준 / BOJ] C++ 27497 알파벳 블록 (0) | 2023.02.20 |
---|---|
[백준 / BOJ] C++ 27496 발머의 피크 이론 (0) | 2023.02.20 |
[백준 / BOJ] C++ 27494 2023년은 검은 토끼의 해 (0) | 2023.02.20 |
[백준 / BOJ] C++ 4485 녹색 옷 입은 애가 젤다지? (0) | 2023.02.20 |
[백준 / BOJ] C++ 18223 민준이와 마산 그리고 건우 (0) | 2023.02.20 |