Published on

๐Ÿ› ๏ธ[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค]-๋‹คํŠธ ๊ฒŒ์ž„

Authors

๐Ÿ“–๋ฌธ์ œ ์„ค๋ช…


์นด์นด์˜คํ†ก ๊ฒŒ์ž„๋ณ„์˜ ํ•˜๋ฐ˜๊ธฐ ์‹ ๊ทœ ์„œ๋น„์Šค๋กœ ๋‹คํŠธ ๊ฒŒ์ž„์„ ์ถœ์‹œํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค. ๋‹คํŠธ ๊ฒŒ์ž„์€ ๋‹คํŠธํŒ์— ๋‹คํŠธ๋ฅผ ์„ธ ์ฐจ๋ก€ ๋˜์ ธ ๊ทธ ์ ์ˆ˜์˜ ํ•ฉ๊ณ„๋กœ ์‹ค๋ ฅ์„ ๊ฒจ๋ฃจ๋Š” ๊ฒŒ์ž„์œผ๋กœ, ๋ชจ๋‘๊ฐ€ ๊ฐ„๋‹จํžˆ ์ฆ๊ธธ ์ˆ˜ ์žˆ๋‹ค. ๊ฐ“ ์ž…์‚ฌํ•œ ๋ฌด์ง€๋Š” ์ฝ”๋”ฉ ์‹ค๋ ฅ์„ ์ธ์ •๋ฐ›์•„ ๊ฒŒ์ž„์˜ ํ•ต์‹ฌ ๋ถ€๋ถ„์ธ ์ ์ˆ˜ ๊ณ„์‚ฐ ๋กœ์ง์„ ๋งก๊ฒŒ ๋˜์—ˆ๋‹ค. ๋‹คํŠธ ๊ฒŒ์ž„์˜ ์ ์ˆ˜ ๊ณ„์‚ฐ ๋กœ์ง์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

  1. ๋‹คํŠธ ๊ฒŒ์ž„์€ ์ด 3๋ฒˆ์˜ ๊ธฐํšŒ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.
  2. ๊ฐ ๊ธฐํšŒ๋งˆ๋‹ค ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์ ์ˆ˜๋Š” 0์ ์—์„œ 10์ ๊นŒ์ง€์ด๋‹ค.
  3. ์ ์ˆ˜์™€ ํ•จ๊ป˜ Single(S), Double(D), Triple(T) ์˜์—ญ์ด ์กด์žฌํ•˜๊ณ  ๊ฐ ์˜์—ญ ๋‹น์ฒจ ์‹œ ์ ์ˆ˜์—์„œ 1์ œ๊ณฑ, 2์ œ๊ณฑ, 3์ œ๊ณฑ (์ ์ˆ˜1์ ์ˆ˜^1 , ์ ์ˆ˜2์ ์ˆ˜^2 , ์ ์ˆ˜3์ ์ˆ˜^3 )์œผ๋กœ ๊ณ„์‚ฐ๋œ๋‹ค.
  4. ์˜ต์…˜์œผ๋กœ ์Šคํƒ€์ƒ() , ์•„์ฐจ์ƒ(#)์ด ์กด์žฌํ•˜๋ฉฐ ์Šคํƒ€์ƒ() ๋‹น์ฒจ ์‹œ ํ•ด๋‹น ์ ์ˆ˜์™€ ๋ฐ”๋กœ ์ „์— ์–ป์€ ์ ์ˆ˜๋ฅผ ๊ฐ 2๋ฐฐ๋กœ ๋งŒ๋“ ๋‹ค. ์•„์ฐจ์ƒ(#) ๋‹น์ฒจ ์‹œ ํ•ด๋‹น ์ ์ˆ˜๋Š” ๋งˆ์ด๋„ˆ์Šค๋œ๋‹ค.
  5. ์Šคํƒ€์ƒ()์€ ์ฒซ ๋ฒˆ์งธ ๊ธฐํšŒ์—์„œ๋„ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ ์ฒซ ๋ฒˆ์งธ ์Šคํƒ€์ƒ()์˜ ์ ์ˆ˜๋งŒ 2๋ฐฐ๊ฐ€ ๋œ๋‹ค. (์˜ˆ์ œ 4๋ฒˆ ์ฐธ๊ณ )
  6. ์Šคํƒ€์ƒ()์˜ ํšจ๊ณผ๋Š” ๋‹ค๋ฅธ ์Šคํƒ€์ƒ()์˜ ํšจ๊ณผ์™€ ์ค‘์ฒฉ๋  ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ ์ค‘์ฒฉ๋œ ์Šคํƒ€์ƒ(*) ์ ์ˆ˜๋Š” 4๋ฐฐ๊ฐ€ ๋œ๋‹ค. (์˜ˆ์ œ 4๋ฒˆ ์ฐธ๊ณ )
  7. ์Šคํƒ€์ƒ(*)์˜ ํšจ๊ณผ๋Š” ์•„์ฐจ์ƒ(#)์˜ ํšจ๊ณผ์™€ ์ค‘์ฒฉ๋  ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ ์ค‘์ฒฉ๋œ ์•„์ฐจ์ƒ(#)์˜ ์ ์ˆ˜๋Š” -2๋ฐฐ๊ฐ€ ๋œ๋‹ค. (์˜ˆ์ œ 5๋ฒˆ ์ฐธ๊ณ )
  8. Single(S), Double(D), Triple(T)์€ ์ ์ˆ˜๋งˆ๋‹ค ํ•˜๋‚˜์”ฉ ์กด์žฌํ•œ๋‹ค.
  9. ์Šคํƒ€์ƒ(*), ์•„์ฐจ์ƒ(#)์€ ์ ์ˆ˜๋งˆ๋‹ค ๋‘˜ ์ค‘ ํ•˜๋‚˜๋งŒ ์กด์žฌํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์กด์žฌํ•˜์ง€ ์•Š์„ ์ˆ˜๋„ ์žˆ๋‹ค.

0~10์˜ ์ •์ˆ˜์™€ ๋ฌธ์ž S, D, T, *, #๋กœ ๊ตฌ์„ฑ๋œ ๋ฌธ์ž์—ด์ด ์ž…๋ ฅ๋  ์‹œ ์ด์ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜๋ผ.

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


์ฃผ์–ด์ง„ ์ž…๋ ฅ ๋ณ€์ˆ˜๋“ค์— ๋Œ€ํ•ด์„œ, for๋ฌธ ์•ˆ์˜ ๋ณ„๋„์˜ order(์ผ์ข…์˜ ํ”Œ๋ž˜๊ทธ)๋ฅผ ๋Œ๋ฆฌ๋ฉด์„œ ์ž…๋ ฅ๋œ ์ ์ˆ˜๋ฅผ ๋ฐ”๋กœ๋ฐ”๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•.

โŒจ๏ธํ’€์ด ์ฝ”๋“œ


def solution(dartResult):
    answer = 0
    point = []
    order = -1
    pivot = False

    for i in range(len(dartResult)):

        if pivot == True:
            pivot = False
            order += 1
            continue

        if dartResult[i] >= "0" and dartResult[i] <= "9":
            if dartResult[i] == "1" and dartResult[i+1] == "0":
                point.append(10)
                pivot = True
                continue
                
            else :
                point.append(int(dartResult[i]))
                order += 1
                continue
                
        if dartResult[i] == "D" :
            point[order] = point[order] ** 2
            continue
        if dartResult[i] == "T" :
            point[order] = point[order] ** 3
            continue

        if order == 0 and dartResult[i] == "*":
            point[order] *= 2
        elif dartResult[i] == "*":
            point[order-1] *= 2
            point[order] *= 2
        if dartResult[i] == "#":
            point[order] *= -1

    for i in point:
        answer += i
            
    return answer

์ถœ์ฒ˜ : ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2018 ์นด์นด์˜ค ๋‹คํŠธ ๊ฒŒ์ž„ ๋ฌธ์ œ