From 426891dfc75b24d9cbdb8a02fe40490cbe22c0ea Mon Sep 17 00:00:00 2001 From: Gyubin Han <89185979+Gyubin-Han@users.noreply.github.com> Date: Tue, 14 May 2024 18:04:28 +0900 Subject: [PATCH] add: swea/1954.py --- swea/1954.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 swea/1954.py diff --git a/swea/1954.py b/swea/1954.py new file mode 100644 index 0000000..92071d3 --- /dev/null +++ b/swea/1954.py @@ -0,0 +1,33 @@ +t=int(input()) + +for tc in range(1,t+1): + n=int(input()) + arr=[[0]*n for _ in range(n)] + count=1 + x=0 + y=0 + lim=n-1 + limcnt=0 + isXy=True + + while count<(n*n)+1: + arr[abs(y)][abs(x)]=count + if limcnt==lim: + if isXy: + x*=-1 + lim-=1 + else: + y*=-1 + isXy=not(isXy) + limcnt=0 + else: + limcnt+=1 + if isXy: + x+=1 + else: + y+=1 + count+=1 + + print("#"+str(tc)) + for a in arr: + print(*a) \ No newline at end of file