#include <iostream>
#include <utility>
using namespace std;
int* getStartPos (int _startPos, int _n) {
int x, y, moveRow, moveCol;
int *info = new int[5];
switch (_startPos) {
case 1 :
info[0] = _startPos;
info[1] = _startPos;
info[2] = 1;
info[3] = 1;
info[4] = true;
break;
case 2 :
info[0] = _n;
info[1] = _startPos;
info[2] = -1;
info[3] = 1;
info[4] = true;
break;
case 3 :
info[0] = _n;
info[1] = _n;
info[2] = -1;
info[3] = -1;
info[4] = false;
break;
case 4 :
info[0] = _startPos;
info[1] = _n;
info[2] = 1;
info[3] = -1;
info[4] = false;
break;
}
return info;
}
int main()
{
int n;
int curRow, curCol, start, startDirection;
int m[10][10] = { 0, };
int maxLoof;
int NORTH = -1;
int SOUTH = 1;
int EAST = 1;
int WEST = -1;
int *info;
int num = 0;
bool moveCol, moveRow, isMovedCol;
cin >> n >> start >> startDirection;
info = getStartPos(start, n);
curRow = info[0];
curCol = info[1];
moveRow = info[2];
moveCol = info[3];
isMovedCol = info[4];
m[curRow][curCol] = num;
maxLoof = 1;
for (int i = 1; i <= (n * n) / 2; ++i) {
if (isMovedCol) {
curCol += moveCol;
} else {
curRow += moveRow;
}
isMovedCol != isMovedCol;
while (maxLoof-- > 0) {
m[curRow][curCol] = num + 1;
}
maxLoof++;
}
return 0;
}
'알고리즘 풀이' 카테고리의 다른 글
백준 2292번 벌집 (0) | 2017.12.06 |
---|---|
백준 2163번 초콜릿 자르기 (0) | 2017.12.04 |
백준 1965번 상자넣기 (0) | 2017.11.29 |
백준 2178번 미로탐색 (0) | 2017.11.27 |
백준 2156번 포도주 시식 (0) | 2017.11.24 |