๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/๋ฐฑ์ค€(BOJ)

[ ํŒŒ์ด์ฌ(python) ] ๋ฐฑ์ค€ 16935 - ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 3

by YWTechIT 2021. 6. 15.
728x90

๐Ÿ“ ๋ฐฑ์ค€ 16935 - ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 3

๋ฐฑ์ค€ 16935 - ๋ฐฐ์—ด๋Œ๋ฆฌ๊ธฐ 3


โšก๏ธ ๋‚˜์˜ ํ’€์ด

2์ฐจ์›๋ฐฐ์—ด์„ ์ƒํ•˜, ์ขŒ์šฐ, ์‹œ๊ณ„ ๋ฐฉํ–ฅ์œผ๋กœ 90๋„ ํšŒ์ „, ๋ฐ˜์‹œ๊ณ„ ๋ฐฉํ–ฅ์œผ๋กœ 90๋„ ํšŒ์ „, ๋ถ€๋ถ„ ๋ฐฐ์—ด ์‹œ๊ณ„๋ฐฉํ–ฅ ํšŒ์ „, ๋ถ€๋ถ„ ๋ฐฐ์—ด ๋ฐ˜์‹œ๊ณ„๋ฐฉํ–ฅ ํšŒ์ „ ํ•˜๋Š” ๋ฌธ์ œ๋‹ค. ์ด ๋ฌธ์ œ๋ฅผ ํ’€ ๋•Œ indexError๋ฅผ ์กฐ์‹ฌํ•˜์ž.

 

3๋ฒˆ, 4๋ฒˆ ์—ฐ์‚ฐ์—์„œ๋Š” ๋ฐ˜๋ณต๋ฌธ์˜ ๋ฒ”์œ„๋ฅผ n, m์„ ์„œ๋กœ ๋ฐ”๊ฟ”์ฃผ์—ˆ๋Š”๋ฐ, n != m ์ผ๋•Œ ๋ฒ”์œ„๊ฐ€ ๋‹ฌ๋ผ์ง€๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๊ทธ๋ž˜์„œ temp ์˜ `n`, `m`๋„ ์„œ๋กœ ์ž๋ฆฌ๋ฅผ ๋ฐ”๊ฟ”์ฃผ์—ˆ๋‹ค. ์ฃผ์˜ํ•  ์ ์€ ๋งˆ์ง€๋ง‰์— oper๋ฅผ ์‹คํ–‰์‹œํ‚ฌ ๋•Œ n, m = m, n์„ ์„ ์–ธํ•ด์ค˜์„œ ๊ฐ€๋กœ, ์„ธ๋กœ๊ฐ€ ๋ฐ”๋€Œ์ง€ ์•Š๊ฒŒ ์„ ์–ธํ•˜์ž.

 

5๋ฒˆ, 6๋ฒˆ ์—ฐ์‚ฐ์€ ์กฐ๊ธˆ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ๋Š”๋ฐ ๊ทœ์น™์„ ์•Œ๋ฉด ์–ด๋ ต์ง€ ์•Š๋‹ค.(๊ทœ์น™์„ ์ฐพ๋Š” ๊ณผ์ •์ด ์–ด๋ ต๊ธด ํ•˜์ง€๋งŒ..๐Ÿ˜…) ๋‹ค์Œ ์‚ฌ์ง„์„ ๋ณด์ž.

 

 

  1. arr๊ณผ ๋ฒ”์œ„๋Š” ๊ฐ™์ง€๋งŒ ๊ฐ’์€ 0์ธ temp๋ฅผ ์„ ์–ธํ•œ๋‹ค.
  2. a๋ฅผ 2๋กœ ์˜ฎ๊ฒจ์•ผํ•˜๋ฏ€๋กœ arr์˜ a ์ขŒํ‘œ๋ฅผ ๊ฐ€์ ธ์˜ฌ ๋ฐ˜๋ณต๋ฌธ์„ ์„ ์–ธํ•œ๋‹ค.
  3. a์˜ ์ฒซ๋ฒˆ์งธ ์ขŒํ‘œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ b์˜ ์ฒซ๋ฒˆ์งธ ์ขŒํ‘œ์™€ ํ•˜๋‚˜์”ฉ ๋„ฃ์„ ์ˆ˜ ์žˆ๊ฒŒ ์„ค์ •ํ•œ๋‹ค.
  4. ๋‚˜๋จธ์ง€ 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)

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€