https://www.acmicpc.net/problem/1022
무난하게 해결한것 같다.
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
int maps[50][5];
int dx[4]{ 0,-1,0,1 };
int dy[4]{ 1,0,-1,0 };
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
int dir = 0, cnt = 1;
int x = 0, y = 0, num = 1, d = 0;
while (maps[0][0] == 0 || maps[0][c2-c1] == 0 || maps[r2-r1][0] == 0 || maps[r2-r1][c2-c1] == 0) {
for (int i = 0; i < cnt; i++) {
if (x >= r1 && x <= r2 && y >= c1 && y <= c2) {
maps[x-r1][y-c1] = num;
}
x += dx[dir];
y += dy[dir];
num++;
}
dir = (dir + 1) % 4;
if (++d == 2) {
d = 0;
cnt++;
}
}
num = max({ maps[0][0], maps[0][c2 - c1], maps[r2 - r1][0], maps[r2 - r1][c2 - c1] });
int prt_format = 0;
while (num != 0) {
prt_format++;
num /= 10;
}
for (int i = 0; i <= r2 - r1; i++) {
for (int j = 0; j <= c2 - c1; j++) {
cout << setw(prt_format) << maps[i][j] << ' ';
}
cout << '\n';
}
}
다른 골드 구현 문제와 비교했을때 평이한 난이도 인듯하다.