#include <iostream>
using namespace std;
void getSnail(int N, int Want)
{
int tmp = N;
int row = -1;
int col = 0;
int dir = 1;
int x = 0, y = 0;
int Square = N * N;
int** arr;
arr = new int* [N];
for (int i = 0; i < N; i++) arr[i] = new int[N];
if (N >= 3 and N <= 999 and N % 2 == 1)
{
while (tmp > 0)
{
for (int i = 0; i < tmp; i++)
{
row = row + dir;
arr[row][col] = Square;
if (Square == Want)
{
x = row + 1;
y = col + 1;
}
Square--;
}
tmp--;
for (int i = 0; i < tmp; i++)
{
col = col + dir;
arr[row][col] = Square;
if (Square == Want)
{
x = row + 1;
y = col + 1;
}
Square--;
}
dir = dir * (-1);
}
for (int i = 0; i < N * N; i++)
{
int r = i / N;
int c = i % N;
cout << arr[r][c] << " ";
if ((i % N) == N - 1) cout << endl;
}
cout << x << " " << y << endl;
for (int i = 0; i < N; i++) delete[] arr[i];
delete[] arr;
}
}
int main(void)
{
int N = 0, Want = 0;
cin >> N;
cin >> Want;
getSnail(N, Want);
return 0;
}
'Computer Science > 백준 알고리즘' 카테고리의 다른 글
[백준] 1979번 소수 찾기 (C++) (0) | 2022.03.14 |
---|---|
[백준] 1935번 후위 표기식2 (파이썬) (0) | 2022.03.14 |
[백준] 3의 배수 (파이썬) (0) | 2022.03.14 |
[백준] 1712번 손익분기점 (C++) (0) | 2022.03.14 |
[백준] 1546번 평균 (C++) (0) | 2022.03.14 |