ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [๋ฐฑ์ค€] 20114 ๋ฏธ์•„ ๋…ธํŠธ with Python
    PS 2022. 5. 15. 02:19
    728x90
    ๋ฐ˜์‘ํ˜•

    ๐Ÿ“Œ BOJ 20114 ๋ฏธ์•„ ๋…ธํŠธ

    ๐Ÿ’ก ์กฐ๊ฑด

    1. ๋…ธํŠธ์— ์ ํžŒ ๋ฌธ์ž์—ด์ด ๋ฒˆ์ง„ ํŒจํ„ด์€ ์ผ์ •ํ–ˆ๋Š”๋ฐ, ๊ฐ€๋ น "abc" ๋ฌธ์ž๊ฐ€ ์„ธ๋กœ๋กœ 3๊ธ€์ž์”ฉ, ๊ฐ€๋กœ๋กœ 2๊ธ€์ž์”ฉ ๋ฒˆ์ง„ ๊ฒฝ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์•˜๋‹ค.

    2. ์•„์‰ฝ๊ฒŒ๋„ ๋ฒˆ์ง„ ๋ฌธ์ž์—ด์˜ ์ผ๋ถ€๋Š” ์ง€์›Œ์ง„ ์ƒํƒœ์˜€๋‹ค.
      ๋„ˆ๋ฌด ๋งŽ์ด ์ง€์›Œ์ ธ๋ฒ„๋ ค์„œ ํ•ด๋‹น ์ž๋ฆฌ์˜ ๋ฌธ์ž๋ฅผ ์œ ์ถ”ํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ, ์™„์ „ํžˆ ๋ฌธ์ž์—ด์„ ๋ณต์›ํ•˜์ง€ ๋ชปํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

    3. ์ฒซ์งธ ์ค„์— ์›๋ž˜ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด N, ์„ธ๋กœ๋กœ ๋ฒˆ์ง„ ๊ธ€์ž์˜ ๊ฐœ์ˆ˜ H, ๊ฐ€๋กœ๋กœ ๋ฒˆ์ง„ ๊ธ€์ž์˜ ๊ฐœ์ˆ˜ W๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.
      (1 โ‰ค N โ‰ค 100, 1 โ‰ค H โ‰ค 10, 1 โ‰ค W โ‰ค 10)

    4. H๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ N ร— W ๊ธธ์ด์˜ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค.
      ๋ฌธ์ž์—ด์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž ๋˜๋Š” '?'๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค.
      '?'๋Š” ํ•ด๋‹น ์ž๋ฆฌ์˜ ๋ฌธ์ž๊ฐ€ ์ง€์›Œ์ง„ ๊ฒฝ์šฐ๋ฅผ ๋œปํ•œ๋‹ค.

    5. ๋ฌธ์ž๊ฐ€ ๋ฒˆ์ง„ ์ž๋ฆฌ์— ๋‘ ๊ฐœ ์ด์ƒ์˜ ๋ฌธ์ž๊ฐ€ ์žˆ๋Š” ๋“ฑ ๋ชจ์ˆœ๋˜๋Š” ๊ฒฝ์šฐ๋Š” ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง€์ง€ ์•Š๋Š”๋‹ค.

    6. ๋ฌธ์ž์—ด, ๊ตฌํ˜„ ์œ ํ˜•์˜ ๋ฌธ์ œ

    ๐Ÿ–ฅ ์†Œ์Šค ์ฝ”๋“œ

    from sys import stdin
    
    n, h, w = map(int, stdin.readline().split())
    arr = [list(stdin.readline().rstrip()) for _ in range(h)]
    
    
    def solve(x):
        global ans
        for i in range(x * w, (x + 1) * w):
            for j in range(h):
                if arr[j][i] != '?':
                    ans += arr[j][i]
                    return
        ans += '?'
        return
    
    
    ans = ''
    for i in range(n):
        solve(i)
    print(ans)

    ๐Ÿ”– ์˜ˆ์ œ ๋ฐ ์‹คํ–‰๊ฒฐ๊ณผ

    ์˜ˆ์ œ

    6 2 3
    ???rrruuu???ttt???
    f?f?rruuu?????t???

    ์‹คํ–‰๊ฒฐ๊ณผ

    fru?t?

    โŒจ๏ธ ๋ฌธ์ œ ํ’€์ด

    1. ์›๋ž˜์˜ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ๋ณต์›ํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

    2. ์›๋ž˜์˜ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋งŒํผ ๋ฐ˜๋ณตํ•˜๋ฉด์„œ ํ•ด๋‹น ๋ฌธ์ž์—ด์˜ ์œ„์น˜(๋ณ€์ˆ˜ x) ๋ถ€ํ„ฐ ๋ฒˆ์ง„๋งŒํผ ๋ฐ˜๋ณต๋ฌธ์„ ํ†ตํ•ด ์›๋ž˜ ๋ฌธ์ž๋ฅผ ์ฐพ๋Š”๋‹ค.

    3. ์›๋ž˜ ๋ฌธ์ž์—ด์˜ ์œ„์น˜ x๋ถ€ํ„ฐ ๊ฐ€๋กœ๋กœ ๋ฒˆ์ง„๋งŒํผ ๋ฐ˜๋ณตํ•˜๊ณ , ์„ธ๋กœ๋กœ ๋ฒˆ์ง„๋งŒํผ ๋˜ ๋ฐ˜๋ณต์„ ํ•˜๋ฉด์„œ ์›๋ž˜ ๋ฌธ์ž์—ด์„ ์ง€๊ธˆ ์ฐพ์„ ์ˆ˜ ์žˆ๋Š”์ง€ ์•Œ์•„๋ณธ๋‹ค.

    4. ans์— ๋ฌธ์ž์—ด์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ฐพ์€ ํ•ด๋‹น ๋ฌธ์ž์—ด์„ ๋„ฃ๊ณ , ์•„๋‹ˆ๋ผ๋ฉด ? ๋ฅผ ๋„ฃ๋Š”๋‹ค.

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.