흔한 좌표 회전 문제이다.
아래, 왼쪽, 왼쪽위 대각선 3개의 경우를 나눠서 풀면 된다.
#include <string>
#include <vector>
using namespace std;
vector<int> solution(int n) {
vector<int> answer;
vector<vector<int>> map(n, vector<int>(n, 0));
int row = -1, col = 0, num = 1;
for(int i = 0; i < n; i++)
for (int j = i; j < n; j++)
{
if (i % 3 == 0)
row++;
else if (i % 3 == 1)
col++;
else
{
row--;
col--;
}
map[row][col] = num++;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (map[i][j] != 0)
answer.push_back(map[i][j]);
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV2 주식가격 (0) | 2022.06.01 |
|---|---|
| [프로그래머스] (C++) LV2 영어 끝말잇기 (0) | 2022.06.01 |
| [프로그래머스] (C++) LV2 2개 이하로 다른 비트 (0) | 2022.06.01 |
| [프로그래머스] (C++) LV2 피로도 (0) | 2022.06.01 |
| [프로그래머스] (C++) LV2 2 x n 타일링 (0) | 2022.05.31 |