๐ ๋ฐฑ์ค 16935 - ๋ฐฐ์ด ๋๋ฆฌ๊ธฐ 3
๋ฐฑ์ค 16935 - ๋ฐฐ์ด๋๋ฆฌ๊ธฐ 3
โก๏ธ ๋์ ํ์ด
2์ฐจ์๋ฐฐ์ด์ ์ํ
, ์ข์ฐ
, ์๊ณ ๋ฐฉํฅ์ผ๋ก 90๋ ํ์
, ๋ฐ์๊ณ ๋ฐฉํฅ์ผ๋ก 90๋ ํ์
, ๋ถ๋ถ ๋ฐฐ์ด ์๊ณ๋ฐฉํฅ ํ์
, ๋ถ๋ถ ๋ฐฐ์ด ๋ฐ์๊ณ๋ฐฉํฅ ํ์
ํ๋ ๋ฌธ์ ๋ค. ์ด ๋ฌธ์ ๋ฅผ ํ ๋ indexError
๋ฅผ ์กฐ์ฌํ์.
3๋ฒ, 4๋ฒ ์ฐ์ฐ์์๋ ๋ฐ๋ณต๋ฌธ์ ๋ฒ์๋ฅผ n
, m
์ ์๋ก ๋ฐ๊ฟ์ฃผ์๋๋ฐ, n != m
์ผ๋ ๋ฒ์๊ฐ ๋ฌ๋ผ์ง๊ธฐ ๋๋ฌธ์ด๋ค. ๊ทธ๋์ temp
์ `n`, `m`๋ ์๋ก ์๋ฆฌ๋ฅผ ๋ฐ๊ฟ์ฃผ์๋ค. ์ฃผ์ํ ์ ์ ๋ง์ง๋ง์ oper
๋ฅผ ์คํ์ํฌ ๋ n, m = m, n
์ ์ ์ธํด์ค์ ๊ฐ๋ก, ์ธ๋ก๊ฐ ๋ฐ๋์ง ์๊ฒ ์ ์ธํ์.
5๋ฒ, 6๋ฒ ์ฐ์ฐ์ ์กฐ๊ธ ์ด๋ ค์ธ ์ ์๋๋ฐ ๊ท์น์ ์๋ฉด ์ด๋ ต์ง ์๋ค.(๊ท์น์ ์ฐพ๋ ๊ณผ์ ์ด ์ด๋ ต๊ธด ํ์ง๋ง..๐ ) ๋ค์ ์ฌ์ง์ ๋ณด์.
arr
๊ณผ ๋ฒ์๋ ๊ฐ์ง๋ง ๊ฐ์ 0์ธtemp
๋ฅผ ์ ์ธํ๋ค.a
๋ฅผ2
๋ก ์ฎ๊ฒจ์ผํ๋ฏ๋กarr
์a
์ขํ๋ฅผ ๊ฐ์ ธ์ฌ ๋ฐ๋ณต๋ฌธ์ ์ ์ธํ๋ค.a
์ ์ฒซ๋ฒ์งธ ์ขํ๋ถํฐ ์์ํด์b
์ ์ฒซ๋ฒ์งธ ์ขํ์ ํ๋์ฉ ๋ฃ์ ์ ์๊ฒ ์ค์ ํ๋ค.- ๋๋จธ์ง
b
,c
,d
์ขํ๋ ๋์ผํ ๊ณผ์ ์ ๊ฑฐ์น๋ค.
def calc_1():
temp = [[0] * m for _ in range(n)]
for i in range(n):
temp[i] = arr[n-1-i]
return temp
def calc_2():
temp = [[0] * m for _ in range(n)]
for i in range(n):
for j in range(m):
temp[i][j] = arr[i][m-1-j]
return temp
def calc_3(arr, n, m):
temp = [[0] * n for _ in range(m)]
for i in range(m):
for j in range(n):
temp[i][j] = arr[n-1-j][i]
return temp
def calc_4(arr, n, m):
temp = [[0] * n for _ in range(m)]
for i in range(m):
for j in range(n):
temp[i][j] = arr[j][m - 1 - i]
return temp
def calc_5():
temp = [[0] * m for _ in range(n)]
for i in range(n // 2): # move position: 1 -> 2
for j in range(m // 2):
temp[i][j + m // 2] = arr[i][j]
for i in range(n // 2): # move position: 2 -> 3
for j in range(m // 2, m):
temp[i + n // 2][j] = arr[i][j]
for i in range(n // 2, n): # move position: 3 -> 4
for j in range(m // 2, m):
temp[i][j - m // 2] = arr[i][j]
for i in range(n // 2, n): # move position: 4 -> 1
for j in range(m // 2):
temp[i - n // 2][j] = arr[i][j]
return temp
def calc_6():
temp = [[0] * m for _ in range(n)]
for i in range(n // 2): # move position: 1 -> 4
for j in range(m // 2):
temp[i + n // 2][j] = arr[i][j]
for i in range(n // 2, n): # move position: 4 -> 3
for j in range(m // 2):
temp[i][j + m // 2] = arr[i][j]
for i in range(n // 2, n): # move position: 3 -> 2
for j in range(m // 2, m):
temp[i - n // 2][j] = arr[i][j]
for i in range(n // 2): # move position: 2 -> 1
for j in range(m // 2, m):
temp[i][j - m // 2] = arr[i][j]
return temp
n, m, r = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]
operation = list(map(int, input().split()))
for oper in operation:
if oper == 1:
arr = calc_1()
elif oper == 2:
arr = calc_2()
elif oper == 3:
arr = calc_3(arr, n, m)
n, m = m, n
elif oper == 4:
arr = calc_4(arr, n, m)
n, m = m, n
elif oper == 5:
arr = calc_5()
else:
arr = calc_6()
for i in arr:
print(*i)
'Algorithm > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ ํ์ด์ฌ(python) ] ๋ฐฑ์ค 11723 - ์งํฉ (0) | 2021.06.16 |
---|---|
[ ํ์ด์ฌ(python) ] ๋ฐฑ์ค 5086 - ๋ฐฐ์์ ์ฝ์ (0) | 2021.06.16 |
[ ํ์ด์ฌ(python) ] ๋ฐฑ์ค 7567 - ๊ทธ๋ฆ (0) | 2021.06.14 |
[ ํ์ด์ฌ(python) ] ๋ฐฑ์ค 5554 - ์ฌ๋ถ๋ฆ ๊ฐ๋ ๊ธธ (0) | 2021.06.11 |
[ ํ์ด์ฌ(python) ] ๋ฐฑ์ค 10833 - ์ฌ๊ณผ (0) | 2021.06.11 |
๋๊ธ