#include <iostream>
#define ARR 10
using namespace std;
int map[ARR][ARR] = { 0, };
int main() {
int test_case = 0;
cin >> test_case;
for (int i = 0; i < test_case; i++)
{
int iSize;
cin >> iSize;//배열의 한 크기만큼.
int iResult = iSize;
int row = 0;
int col=-1;
int dir = 1;
int iCnt=1;
while (iSize > 0)
{
for (int j = 0; j < iSize; j++)//row 는 그대로, col ++하며 첫줄 진행
{
col = col +dir;
map[row][col] = iCnt;//증가하는 방향이다.
iCnt++;
}
iSize--;
for (int j = 0; j < iSize; j++)
{
row = row + dir;
map[row][col] = iCnt;
iCnt++;
}
dir *= -1;//이제 감소하는 방향임
}
cout << "#" << i + 1 << endl;
for (int j = 0; j < iResult; j++)
{
for (int k = 0; k < iResult; k++)
{
cout << map[j][k]<<" ";
}
cout << endl;
}
}
return 0 ;
}
이문제 못풀었다.
아이디어가 중요하다.
방향바꾸는거로 안하면 복잡하니까 이렇게 하는게 편하다
while(iSize)
{
row 그대로
colum 은 row의 size-1
}