๐ก 1460 ~ 1467์ ์ด์ ๊ฒ์๋ฌผ์ ์ฐธ๊ณ ํด์ฃผ์ธ์!
๐ 1468 : [ ๊ธฐ์ด - ๋ฐฐ์ด ์ฐ์ต ] 2์ฐจ์ ๋ฐฐ์ด ์ง๊ทธ์ฌ๊ทธ ์ฑ์ฐ๊ธฐ 2-1
์ง๊ทธ์ฌ๊ทธ๋ก๋ ์ด๋ป๊ฒ ์ฑ์์ผํ ๊น?๋ฅผ ๊ณ ๋ฏผํ๋ค๊ฐ i๊ฐ ํ์์ด๊ฑฐ๋ ์ง์์ผ ๋๋ก ๋๋ ์ ์์ฑํ๋ค. ํ์ง๋ง, ๊ทธ๊ฒ๋ณด๋ค flag
๋ฅผ ์ฌ์ฉํ๋ฉด ๋ ํธํ๊ฒ ์ฑ์ธ ์ ์๋ค.
flag
๋ ์ ๊ตฌ๋ฅผ on/off
์ค์์น๋ก ๋๊ณ ์ผค ์ ์๋ฏ์ด flag
๋ฅผ ์ฌ์ฉํด์ ๋ฐฉํฅ์ด ๋ฐ๋๋ฉด False
๋ก ์ค์ ํ๊ณ ๋ฐ๋์ผ ๊ฒฝ์ฐ์๋ True
๋ก ์ค์ ํด ์ํ๋ ๋ฐฉํฅ์ผ๋ก ์ ๋ ํ ์ ์๋ค.
ํ์์ flag
๋ฅผ ์ ์ฌ์ฉํ์ง ์์์ ๋ชฐ๋๋๋ฐ ๊ด์ฐฎ์ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ๋ค. ์ ์ฒด์ ์ธ ํ๋ฆ์ด ๋ ๊ฐ์ง๋ก ๋๋ ์ก์ ๋ ์ฌ์ฉํด๋ด์ผ๊ฒ ๋ค. ํ์ฌ ์ฝ๋์์๋ flag = True
์ผ๋๋ ์๋ฐฉํฅ์ผ๋ก flag = False
์ผ๋๋ ์ญ๋ฐฉํฅ์ผ๋ก ์ค์ ํ๋ค. ๋๋จธ์ง ๋ฌธ์ ๋ค์ ์์์ ํ์๋ ๋ฌธ์ ๋ค๊ณผ ๋์ผํ๋ค.
# flag ์ฌ์ฉ
n = int(input())
arr = [[0] * n for _ in range(n)]
flag = True
cnt = 0
for i in range(n):
if flag:
for j in range(n):
cnt += 1
arr[i][j] = cnt
flag = False
else:
for j in range(n-1, -1, -1):
cnt += 1
arr[i][j] = cnt
flag = True
for i in arr:
for j in i:
print(j, end=' ')
print()
# ํ ์ง ํ๋ณ
n = int(input())
arr = [[0] * n for _ in range(n)]
cnt = 0
for i in range(n):
if i % 2:
for j in range(n-1, -1, -1):
cnt += 1
arr[i][j] = cnt
else:
for j in range(n):
cnt += 1
arr[i][j] = cnt
for i in arr:
print(*i, ' ')
๐ 1469 : [ ๊ธฐ์ด - ๋ฐฐ์ด ์ฐ์ต ] 2์ฐจ์ ๋ฐฐ์ด ์ง๊ทธ์ฌ๊ทธ ์ฑ์ฐ๊ธฐ 2-2
n = int(input())
arr = [[0] * n for _ in range(n)]
flag = False
cnt = 0
for i in range(n):
if not flag:
for j in range(n-1, -1, -1):
cnt += 1
arr[i][j] = cnt
flag = True
else:
for j in range(n):
cnt += 1
arr[i][j] = cnt
flag = False
for i in arr:
print(*i, ' ')
๐ 1470 : [ ๊ธฐ์ด - ๋ฐฐ์ด์ฐ์ต ] 2์ฐจ์ ๋ฐฐ์ด ์ง๊ทธ์ฌ๊ทธ ์ฑ์ฐ๊ธฐ 2-3
n = int(input())
arr = [[0] * n for _ in range(n)]
flag = True
cnt = 0
for i in range(n):
if flag:
for j in range(n):
cnt += 1
arr[j][i] = cnt
flag = False
else:
for j in range(n-1, -1, -1):
cnt += 1
arr[j][i] = cnt
flag = True
for i in arr:
print(*i, ' ')
๐ 1471 : [ ๊ธฐ์ด - ๋ฐฐ์ด์ฐ์ต ] 2์ฐจ์ ๋ฐฐ์ด ์ง๊ทธ์ฌ๊ทธ ์ฑ์ฐ๊ธฐ 2-4
n = int(input())
arr = [[0] * n for _ in range(n)]
flag = True
cnt = 0
for i in range(n):
if flag:
for j in range(n-1, -1, -1):
cnt += 1
arr[j][i] = cnt
flag = False
else:
for j in range(n):
cnt += 1
arr[j][i] = cnt
flag = True
for i in arr:
print(*i, ' ')
๐ 1472 : [ ๊ธฐ์ด - ๋ฐฐ์ด์ฐ์ต ] 2์ฐจ์ ๋ฐฐ์ด ์ง๊ทธ์ฌ๊ทธ ์ฑ์ฐ๊ธฐ 2-5
ํ๋ ฌ์ ํฌ๊ธฐ๊ฐ n*m
์ผ๋๋ ๋ง์ฐฌ๊ฐ์ง๋ก ๊ฐ๋ก๋ก ๊ฐ์ด ์ฑ n
์ ๋จผ์ ๋ฐ๋ณต๋ฌธ์ ์์ฑํ๊ณ arr[i][j]
๋ฅผ ๋ฃ์ผ๋ฉด ๋๋ค. ๋ฐ๋์ ๊ฒฝ์ฐ๋ m
์ ๋จผ์ ๋ฐ๋ณต๋ฌธ์ ์์ฑํ๊ณ arr[j][i]
์ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
n, m = map(int, input().split())
arr = [[0] * m for _ in range(n)]
flag = True
cnt = 0
for i in range(n - 1, -1, -1):
if flag:
for j in range(m-1, -1, -1):
cnt += 1
arr[i][j] = cnt
flag = False
else:
for j in range(m):
cnt += 1
arr[i][j] = cnt
flag = True
for i in arr:
print(*i, ' ')
๐ 1473 : [ ๊ธฐ์ด - ๋ฐฐ์ด ์ฐ์ต ] 2์ฐจ์ ๋ฐฐ์ด ์ง๊ทธ์ฌ๊ทธ ์ฑ์ฐ๊ธฐ 2-6
n, m = map(int, input().split())
arr = [[0] * m for _ in range(n)]
cnt = 0
flag = True
for i in range(n-1, -1, -1):
if flag:
for j in range(m):
cnt += 1
arr[i][j] = cnt
flag = False
else:
for j in range(m-1, -1, -1):
cnt += 1
arr[i][j] = cnt
flag = True
for i in arr:
print(*i, ' ')
๐ 1474 : [ ๊ธฐ์ด - ๋ฐฐ์ด์ฐ์ต ] 2์ฐจ์ ๋ฐฐ์ด ์ง๊ทธ์ฌ๊ทธ ์ฑ์ฐ๊ธฐ 2-7
n, m = map(int, input().split())
arr = [[0] * m for _ in range(n)]
flag = True
cnt = 0
for i in range(m - 1, -1, -1):
if flag:
for j in range(n - 1, -1, -1):
cnt += 1
arr[j][i] = cnt
flag = False
else:
for j in range(n):
cnt += 1
arr[j][i] = cnt
flag = True
for i in arr:
print(*i, ' ')
๐ 1475 : [ ๊ธฐ์ด - ๋ฐฐ์ด์ฐ์ต ] 2์ฐจ์ ๋ฐฐ์ด ์ง๊ทธ์ฌ๊ทธ ์ฑ์ฐ๊ธฐ 2-8
n, m = map(int, input().split())
arr = [[0] * m for _ in range(n)]
cnt = 0
flag = True
for i in range(m-1, -1, -1):
if flag:
for j in range(n):
cnt += 1
arr[j][i] = cnt
flag = False
else:
for j in range(n-1, -1, -1):
cnt += 1
arr[j][i] = cnt
flag = True
for i in arr:
print(*i, ' ')
2์ฐจ์ ๋ฐฐ์ด ์ง๊ทธ์ฌ๊ทธ ๋ฐฉ์์ผ๋ก ์ฑ์ฐ๋ ๋ฒ์ ์์๊ณ , ๋ค์์๋ ๋น๊ธ ์ฑ์ฐ๊ธฐ ๋ฐฉ๋ฒ์ ๊ณต๋ถํด๋ณด์.
๋๊ธ