๋‚ด ์ธ์ƒ์—์„œ ๋ฏฟ์„ ๊ฑด ์˜ค์ง ๋‚˜ ์ž์‹ ๋ฟ!

The only one you can truly trust is yourself.

๊ฒŒ์ž„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค [3์ฐจ] ๋ฐฉ๊ธˆ๊ทธ๊ณก (2018 KAKAO BLIND RECRUITMENT, ๋ฌธ์ž์—ด ๋ณ€ํ™˜

๐ŸŽฎinspirer9 2023. 2. 28. 22:44
728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ ์„ค๋ช…

๋ผ๋””์˜ค๋ฅผ ์ž์ฃผ ๋“ฃ๋Š” ๋„ค์˜ค๋Š” ๋ผ๋””์˜ค์—์„œ ๋ฐฉ๊ธˆ ๋‚˜์™”๋˜ ์Œ์•…์ด ๋ฌด์Šจ ์Œ์•…์ธ์ง€ ๊ถ๊ธˆํ•ด์งˆ ๋•Œ๊ฐ€ ๋งŽ๋‹ค. ๊ทธ๋Ÿด ๋•Œ ๋„ค์˜ค๋Š” ๋‹ค์Œ ํฌํ„ธ์˜ '๋ฐฉ๊ธˆ๊ทธ๊ณก' ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•˜๊ณค ํ•œ๋‹ค. ๋ฐฉ๊ธˆ๊ทธ๊ณก์—์„œ๋Š” TV, ๋ผ๋””์˜ค ๋“ฑ์—์„œ ๋‚˜์˜จ ์Œ์•…์— ๊ด€ํ•ด ์ œ๋ชฉ ๋“ฑ์˜ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋Š” ์„œ๋น„์Šค์ด๋‹ค.

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

  • ๋ฐฉ๊ธˆ๊ทธ๊ณก ์„œ๋น„์Šค์—์„œ๋Š” ์Œ์•… ์ œ๋ชฉ, ์žฌ์ƒ์ด ์‹œ์ž‘๋˜๊ณ  ๋๋‚œ ์‹œ๊ฐ, ์•…๋ณด๋ฅผ ์ œ๊ณตํ•œ๋‹ค.
  • ๋„ค์˜ค๊ฐ€ ๊ธฐ์–ตํ•œ ๋ฉœ๋กœ๋””์™€ ์•…๋ณด์— ์‚ฌ์šฉ๋˜๋Š” ์Œ์€ C, C#, D, D#, E, F, F#, G, G#, A, A#, B 12๊ฐœ์ด๋‹ค.
  • ๊ฐ ์Œ์€ 1๋ถ„์— 1๊ฐœ์”ฉ ์žฌ์ƒ๋œ๋‹ค. ์Œ์•…์€ ๋ฐ˜๋“œ์‹œ ์ฒ˜์Œ๋ถ€ํ„ฐ ์žฌ์ƒ๋˜๋ฉฐ ์Œ์•… ๊ธธ์ด๋ณด๋‹ค ์žฌ์ƒ๋œ ์‹œ๊ฐ„์ด ๊ธธ ๋•Œ๋Š” ์Œ์•…์ด ๋Š๊น€ ์—†์ด ์ฒ˜์Œ๋ถ€ํ„ฐ ๋ฐ˜๋ณตํ•ด์„œ ์žฌ์ƒ๋œ๋‹ค. ์Œ์•… ๊ธธ์ด๋ณด๋‹ค ์žฌ์ƒ๋œ ์‹œ๊ฐ„์ด ์งง์„ ๋•Œ๋Š” ์ฒ˜์Œ๋ถ€ํ„ฐ ์žฌ์ƒ ์‹œ๊ฐ„๋งŒํผ๋งŒ ์žฌ์ƒ๋œ๋‹ค.
  • ์Œ์•…์ด 00:00๋ฅผ ๋„˜๊ฒจ์„œ๊นŒ์ง€ ์žฌ์ƒ๋˜๋Š” ์ผ์€ ์—†๋‹ค.
  • ์กฐ๊ฑด์ด ์ผ์น˜ํ•˜๋Š” ์Œ์•…์ด ์—ฌ๋Ÿฌ ๊ฐœ์ผ ๋•Œ์—๋Š” ๋ผ๋””์˜ค์—์„œ ์žฌ์ƒ๋œ ์‹œ๊ฐ„์ด ์ œ์ผ ๊ธด ์Œ์•… ์ œ๋ชฉ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์žฌ์ƒ๋œ ์‹œ๊ฐ„๋„ ๊ฐ™์„ ๊ฒฝ์šฐ ๋จผ์ € ์ž…๋ ฅ๋œ ์Œ์•… ์ œ๋ชฉ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  • ์กฐ๊ฑด์ด ์ผ์น˜ํ•˜๋Š” ์Œ์•…์ด ์—†์„ ๋•Œ์—๋Š” “(None)”์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

์ œํ•œ ์‚ฌํ•ญ

์ž…๋ ฅ ํ˜•์‹

์ž…๋ ฅ์œผ๋กœ ๋„ค์˜ค๊ฐ€ ๊ธฐ์–ตํ•œ ๋ฉœ๋กœ๋””๋ฅผ ๋‹ด์€ ๋ฌธ์ž์—ด m๊ณผ ๋ฐฉ์†ก๋œ ๊ณก์˜ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ๋ฐฐ์—ด musicinfos๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

  • m์€ ์Œ 1๊ฐœ ์ด์ƒ 1439๊ฐœ ์ดํ•˜๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.
  • musicinfos๋Š” 100๊ฐœ ์ดํ•˜์˜ ๊ณก ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ๋ฐฐ์—ด๋กœ, ๊ฐ๊ฐ์˜ ๊ณก ์ •๋ณด๋Š” ์Œ์•…์ด ์‹œ์ž‘ํ•œ ์‹œ๊ฐ, ๋๋‚œ ์‹œ๊ฐ, ์Œ์•… ์ œ๋ชฉ, ์•…๋ณด ์ •๋ณด๊ฐ€ ','๋กœ ๊ตฌ๋ถ„๋œ ๋ฌธ์ž์—ด์ด๋‹ค.
    • ์Œ์•…์˜ ์‹œ์ž‘ ์‹œ๊ฐ๊ณผ ๋๋‚œ ์‹œ๊ฐ์€ 24์‹œ๊ฐ„ HH:MM ํ˜•์‹์ด๋‹ค.
    • ์Œ์•… ์ œ๋ชฉ์€ ',' ์ด์™ธ์˜ ์ถœ๋ ฅ ๊ฐ€๋Šฅํ•œ ๋ฌธ์ž๋กœ ํ‘œํ˜„๋œ ๊ธธ์ด 1 ์ด์ƒ 64 ์ดํ•˜์˜ ๋ฌธ์ž์—ด์ด๋‹ค.
    • ์•…๋ณด ์ •๋ณด๋Š” ์Œ 1๊ฐœ ์ด์ƒ 1439๊ฐœ ์ดํ•˜๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

์ถœ๋ ฅ ํ˜•์‹

์กฐ๊ฑด๊ณผ ์ผ์น˜ํ•˜๋Š” ์Œ์•… ์ œ๋ชฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ

m musicinfos answer
"ABCDEFG" ["12:00,12:14,HELLO,CDEFGAB", "13:00,13:05,WORLD,ABCDEF"] "HELLO"
"CC#BCC#BCC#BCC#B" ["03:00,03:30,FOO,CC#B", "04:00,04:08,BAR,CC#BCC#BCC#B"] "FOO"
"ABC" ["12:00,12:14,HELLO,C#DEFGAB", "13:00,13:05,WORLD,ABCDEF"] "WORLD"

์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

์ฒซ ๋ฒˆ์งธ ์˜ˆ์‹œ์—์„œ HELLO๋Š” ๊ธธ์ด๊ฐ€ 7๋ถ„์ด์ง€๋งŒ 12:00๋ถ€ํ„ฐ 12:14๊นŒ์ง€ ์žฌ์ƒ๋˜์—ˆ์œผ๋ฏ€๋กœ ์‹ค์ œ๋กœ CDEFGABCDEFGAB๋กœ ์žฌ์ƒ๋˜์—ˆ๊ณ , ์ด ์ค‘์— ๊ธฐ์–ตํ•œ ๋ฉœ๋กœ๋””์ธ ABCDEFG๊ฐ€ ๋“ค์–ด์žˆ๋‹ค. ์„ธ ๋ฒˆ์งธ ์˜ˆ์‹œ์—์„œ HELLO๋Š” C#DEFGABC#DEFGAB๋กœ, WORLD๋Š” ABCDE๋กœ ์žฌ์ƒ๋˜์—ˆ๋‹ค. HELLO ์•ˆ์— ์žˆ๋Š” ABC#์€ ๊ธฐ์–ตํ•œ ๋ฉœ๋กœ๋””์ธ ABC์™€ ์ผ์น˜ํ•˜์ง€ ์•Š๊ณ , WORLD ์•ˆ์— ์žˆ๋Š” ABC๊ฐ€ ๊ธฐ์–ตํ•œ ๋ฉœ๋กœ๋””์™€ ์ผ์น˜ํ•œ๋‹ค.

ํ’€์ด

  • ๋ฌธ์ œ ์„ค๋ช…์ด ๋„ˆ๋ฌด ์–ด๋ ค์šด๋ฐ
  • 1ํŠธ - ์‹คํŒจ...
def SharpRemover(s):
    s = list(s)
    for i in reversed(range(1,len(s))):
        if s[i] == "#":
            s[i-1] = chr(ord(s[i-1]) +32)
            s.pop(i)
    return ''.join(s)

def solution(m, musicinfos):
    m = SharpRemover(m)
    answer = ''
    for mi in musicinfos:
        time1, time2, title, melody = mi.split(',')
        melody = SharpRemover(melody)
        time = (int(time2[:2])*60 + int(time2[-2:])) - (int(time1[:2]) * 60 + int(time1[-2:]))
        if time > len(melody):
            melody = melody * (time//len(melody))
            melody += melody[0:time%len(melody)]
        if m in melody:
            answer = title
    return answer
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	์‹คํŒจ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.5MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.10ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.2MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.15ms, 10.3MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	์‹คํŒจ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.5MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.3MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.2MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (0.13ms, 10.3MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (0.49ms, 10.3MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	์‹คํŒจ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (0.14ms, 10.4MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	์‹คํŒจ (0.10ms, 10.3MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	์‹คํŒจ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	์‹คํŒจ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.4MB)
ํ…Œ์ŠคํŠธ 26 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 27 ใ€‰	์‹คํŒจ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 28 ใ€‰	์‹คํŒจ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 29 ใ€‰	์‹คํŒจ (4.62ms, 10.4MB)
ํ…Œ์ŠคํŠธ 30 ใ€‰	ํ†ต๊ณผ (4.35ms, 10.3MB)
  • ๋œฏ์–ด๊ณ ์ณ์„œ ํ…Œ์ผ€ 30๋ฒˆ ๋นผ๊ณ ๋Š” ๋‹ค ํ†ต๊ณผ๋˜๋Š”๋ฐ... 30๋ฒˆ์€ ์™œ ์•ˆ๋˜์ง€?
def SharpRemover(s):
    s = list(s)
    for i in reversed(range(1,len(s))):
        if s[i] == "#":
            s[i-1] = chr(ord(s[i-1]) +32)
            s.pop(i)
    return ''.join(s)

def solution(m, musicinfos):
    m = SharpRemover(m)
    answer = ''
    playtime = 0
    for mi in musicinfos:
        time1, time2, title, melody = mi.split(',')
        melody = SharpRemover(melody)
        time1 = int(time1[:2]) * 60 + int(time1[-2:])
        time2 = int(time2[:2]) * 60 + int(time2[-2:])
        time = time2 - time1
        if time < 0:
            time += 24*60
        if time > len(melody):
            melody = melody * (time//len(melody))
            melody += melody[0:time%len(melody)]
        if m in melody:
            if time > playtime:
                playtime = time
                answer = title
    if answer == '':
        answer = "(None)"
    return answer
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.4MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.4MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.2MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.13ms, 10.2MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.30ms, 10.4MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.3MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.14ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.17ms, 10.3MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.4MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.4MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (0.26ms, 10.3MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.2MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.4MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 26 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.2MB)
ํ…Œ์ŠคํŠธ 27 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 28 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.5MB)
ํ…Œ์ŠคํŠธ 29 ใ€‰	ํ†ต๊ณผ (4.72ms, 10.4MB)
ํ…Œ์ŠคํŠธ 30 ใ€‰	์‹คํŒจ (5.44ms, 10.2MB)
  • ํ•˜ํ•˜ํ•˜... ์ œ๋Œ€๋กœ ์•ˆ์ฝ์ฃ ?
    • ์กฐ๊ฑด์ด ์ผ์น˜ํ•˜๋Š” ์Œ์•…์ด ์—ฌ๋Ÿฌ ๊ฐœ์ผ ๋•Œ์—๋Š” ๋ผ๋””์˜ค์—์„œ ์žฌ์ƒ๋œ ์‹œ๊ฐ„์ด ์ œ์ผ ๊ธด ์Œ์•… ์ œ๋ชฉ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
    • ์žฌ์ƒ๋œ ์‹œ๊ฐ„๋„ ๊ฐ™์„ ๊ฒฝ์šฐ ๋จผ์ € ์ž…๋ ฅ๋œ ์Œ์•… ์ œ๋ชฉ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
      • ๊ฑฐ๊ธฐ์— ํ•˜๋‚˜ ๋” ํ”Œ๋Ÿฌ์Šค
        • ๋“ค์—ˆ๋˜ ๋ฉœ๋กœ๋””๋ณด๋‹ค ๋ผ๋””์˜ค์—์„œ ๋‚˜์˜จ ์Œ์•…์ด ๋” ๊ธธ ๊ฒฝ์šฐ์—๋„ ์ž˜๋ผ์ฃผ์–ด์•ผ ํ•œ๋‹ค.
def SharpRemover(s):
    s = list(s)
    for i in reversed(range(1,len(s))):
        if s[i] == "#":
            s[i-1] = chr(ord(s[i-1]) +32)
            s.pop(i)
    return ''.join(s)

def solution(m, musicinfos):
    m = SharpRemover(m)
    answer = ''
    playtime = 0
    for mi in musicinfos:
        time1, time2, title, melody = mi.split(',')
        melody = SharpRemover(melody)
        time1 = int(time1[:2]) * 60 + int(time1[-2:])
        time2 = int(time2[:2]) * 60 + int(time2[-2:])
        time = time2 - time1
        len_melody = len(melody)
        if time > len_melody:
            melody = melody * (time//len_melody)
            melody += melody[0:time%len_melody]
        else:
            melody = melody[0:time]
        if m in melody:
            if time > playtime:
                answer = title
                playtime = time

    if answer == '':
        answer = "(None)"
    return answer
  • ํ•จ์ • ๊ฐ™์•˜๋˜ ๋ฌธ์ œ ํด๋ฆฌ์–ด
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.3MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.3MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.4MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.3MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.16ms, 10.4MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.4MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.12ms, 10.3MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.2MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.3MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.3MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (0.25ms, 10.5MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.2MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.2MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.4MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 26 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 27 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.4MB)
ํ…Œ์ŠคํŠธ 28 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.4MB)
ํ…Œ์ŠคํŠธ 29 ใ€‰	ํ†ต๊ณผ (4.88ms, 10.3MB)
ํ…Œ์ŠคํŠธ 30 ใ€‰	ํ†ต๊ณผ (4.42ms, 10.5MB)
  • ๊ณ ์ˆ˜์˜ ์ฝ”๋“œ
    • ์งง์•„์„œ ๊ทธ๋ ‡์ง€ ๋น„์Šทํ•จ.
    • ๊ธ€๊ณ ๋ณด๋‹ˆ replace ์“ธ๊ฑธ...
def shap_to_lower(s):
    s = s.replace('C#','c').replace('D#','d').replace('F#','f').replace('G#','g').replace('A#','a')
    return s

def solution(m,musicinfos):
    answer=[0,'(None)']   # time_len, title
    m = shap_to_lower(m)
    for info in musicinfos:
        split_info = info.split(',')
        time_length = (int(split_info[1][:2])-int(split_info[0][:2]))*60+int(split_info[1][-2:])-int(split_info[0][-2:])
        title = split_info[2]
        part_notes = shap_to_lower(split_info[-1])
        full_notes = part_notes*(time_length//len(part_notes))+part_notes[:time_length%len(part_notes)]
        if m in full_notes and time_length>answer[0]:
            answer=[time_length,title]
    return answer[-1]
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.5MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.5MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.2MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.3MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.5MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.3MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.5MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.5MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (0.10ms, 10.5MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.4MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (0.09ms, 10.3MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.5MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 26 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
ํ…Œ์ŠคํŠธ 27 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
ํ…Œ์ŠคํŠธ 28 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.5MB)
ํ…Œ์ŠคํŠธ 29 ใ€‰	ํ†ต๊ณผ (1.23ms, 10.4MB)
ํ…Œ์ŠคํŠธ 30 ใ€‰	ํ†ต๊ณผ (1.17ms, 10.4MB)

ใ…‹์นด์นด์˜ค ๋ฌธ์ œ๋Š” ๋ฌธ์ œ ์ฝ๊ณ  ํ•ด์„ํ•˜๋Š” ์ž‘์—…์ด ๋” ์˜ค๋ž˜ ๊ฑธ๋ฆผ

728x90
๋ฐ˜์‘ํ˜•