๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • What would life be If we had no courage to attemp anything?
Problem Solving/PROGRAMMERS

[python]ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ๋ฐฉ๊ธˆ๊ทธ๊ณก

by DevIseo 2022. 8. 24.

[python]ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ๋ฐฉ๊ธˆ๊ทธ๊ณก

https://school.programmers.co.kr/learn/courses/30/lessons/17683

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

def transfer(code):
    if 'C#' in code:
        code = code.replace('C#','c')
    if 'D#' in code:
        code = code.replace('D#','d')
    if 'F#' in code:
        code = code.replace('F#','f')
    if 'G#' in code:
        code = code.replace('G#','g')
    if 'A#' in code:
        code = code.replace('A#','a')
    
    return code

def solution(m, musicinfos):
    m = transfer(m)
    # ์กฐ๊ฑด์ด ์ผ์น˜ํ•˜๋Š” ์Œ์•…์ด ์—†์„ ๋•Œ์—๋Š” “(None)”์„ ๋ฐ˜ํ™˜
    answer = ('(None)',None)
    for info in musicinfos:
        start, end, title, code = info.split(",")
        start_h, start_m = map(int,start.split(":"))
        end_h,end_m = map(int,end.split(":"))
        time = 60*(end_h-start_h) + (end_m-start_m)
        
        #'#'์ด ์žˆ์œผ๋ฉด ์†Œ๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๊ธฐ!
        code = transfer(code)
        # ๋ฉœ๋กœ๋”” ๋ฐ˜๋ณต์‹œํ‚ค๊ณ  ์ž๋ฅด๊ธฐ
        play = (code*time)[:time]

        #์ฐพ๊ณ ์ž ํ•˜๋Š” ๋ฉœ๋กœ๋””๊ฐ€ ์กด์žฌํ•œ๋‹ค๋ฉด...
        if m in play:
            if (answer[1] == None) or (time > answer[1]):
                answer = (title, time)
                print(answer)
            

    return answer[0]

๋Œ“๊ธ€