ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฐ˜์‘ํ˜•

๋ฌธ์ œ ์„ค๋ช…

์ˆ˜ํฌ์ž๋Š” ์ˆ˜ํ•™์„ ํฌ๊ธฐํ•œ ์‚ฌ๋žŒ์˜ ์ค€๋ง์ž…๋‹ˆ๋‹ค. ์ˆ˜ํฌ์ž ์‚ผ์ธ๋ฐฉ์€ ๋ชจ์˜๊ณ ์‚ฌ์— ์ˆ˜ํ•™ ๋ฌธ์ œ๋ฅผ ์ „๋ถ€ ์ฐ์œผ๋ ค ํ•ฉ๋‹ˆ๋‹ค. ์ˆ˜ํฌ์ž๋Š” 1๋ฒˆ ๋ฌธ์ œ๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ๋ฌธ์ œ๊นŒ์ง€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฐ์Šต๋‹ˆ๋‹ค.

1๋ฒˆ ์ˆ˜ํฌ์ž๊ฐ€ ์ฐ๋Š” ๋ฐฉ์‹: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
2๋ฒˆ ์ˆ˜ํฌ์ž๊ฐ€ ์ฐ๋Š” ๋ฐฉ์‹: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ...
3๋ฒˆ ์ˆ˜ํฌ์ž๊ฐ€ ์ฐ๋Š” ๋ฐฉ์‹: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ...

1๋ฒˆ ๋ฌธ์ œ๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ๋ฌธ์ œ๊นŒ์ง€์˜ ์ •๋‹ต์ด ์ˆœ์„œ๋Œ€๋กœ ๋“ค์€ ๋ฐฐ์—ด answers๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๋งŽ์€ ๋ฌธ์ œ๋ฅผ ๋งžํžŒ ์‚ฌ๋žŒ์ด ๋ˆ„๊ตฌ์ธ์ง€ ๋ฐฐ์—ด์— ๋‹ด์•„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ ์กฐ๊ฑด

  • ์‹œํ—˜์€ ์ตœ๋Œ€ 10,000 ๋ฌธ์ œ๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ฌธ์ œ์˜ ์ •๋‹ต์€ 1, 2, 3, 4, 5์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
  • ๊ฐ€์žฅ ๋†’์€ ์ ์ˆ˜๋ฅผ ๋ฐ›์€ ์‚ฌ๋žŒ์ด ์—ฌ๋Ÿฟ์ผ ๊ฒฝ์šฐ, returnํ•˜๋Š” ๊ฐ’์„ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•ด์ฃผ์„ธ์š”.

์ž…์ถœ๋ ฅ ์˜ˆ

answersreturn

[1,2,3,4,5] [1]
[1,3,2,4,2] [1,2,3]

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

์ž…์ถœ๋ ฅ ์˜ˆ #1

  • ์ˆ˜ํฌ์ž 1์€ ๋ชจ๋“  ๋ฌธ์ œ๋ฅผ ๋งžํ˜”์Šต๋‹ˆ๋‹ค.
  • ์ˆ˜ํฌ์ž 2๋Š” ๋ชจ๋“  ๋ฌธ์ œ๋ฅผ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค.
  • ์ˆ˜ํฌ์ž 3์€ ๋ชจ๋“  ๋ฌธ์ œ๋ฅผ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ๊ฐ€์žฅ ๋ฌธ์ œ๋ฅผ ๋งŽ์ด ๋งžํžŒ ์‚ฌ๋žŒ์€ ์ˆ˜ํฌ์ž 1์ž…๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ #2

  • ๋ชจ๋“  ์‚ฌ๋žŒ์ด 2๋ฌธ์ œ์”ฉ์„ ๋งž์ท„์Šต๋‹ˆ๋‹ค.
def solution(answers):
    
    # 1๋ฒˆ, 2๋ฒˆ, 3๋ฒˆ ํ•™์ƒ์˜ ๋‹ต์•ˆ์ง€
    student_answers = []
    student_answers.append([1,2,3,4,5] * 2000) # 1๋ฒˆ ํ•™์ƒ
    student_answers.append([2,1,2,3,2,4,2,5] * 1250) # 2๋ฒˆ ํ•™์ƒ
    student_answers.append([3,3,1,1,2,2,4,4,5,5] * 1000) # 3๋ฒˆ ํ•™์ƒ
    
    # 1๋ฒˆ, 2๋ฒˆ, 3๋ฒˆ ํ•™์ƒ์˜ ์ •๋‹ต ๊ฐœ์ˆ˜
    count = [0,0,0]
    
    # ๊ฐ ํ•™์ƒ์— ๋Œ€ํ•ด์„œ, ํ•˜๋‚˜์”ฉ ์ •๋‹ต์„ ํ™•์ธํ•˜๋ฉฐ ๋งž์ถ˜ ๊ฐœ์ˆ˜๋ฅผ ์นด์šดํŠธ
    for i in range(3):
        for j in range(len(answers)):
            if student_answers[i][j] == answers[j]:
                count[i] += 1
            
    # ๊ฐ€์žฅ ๋งŽ์ด ๋งž์ถ˜ ํ•™์ƒ๋“ค์˜ ๋ฒˆํ˜ธ๋ฅผ ๋ฐ˜ํ™˜
    answer = []
    for i in range(3):
        if count[i] == max(count):
            answer.append(i + 1)
    
    return answer

 

def solution(answers):
    
    # 1๋ฒˆ, 2๋ฒˆ, 3๋ฒˆ ํ•™์ƒ์˜ ๋‹ต์•ˆ์ง€
    student_answers = []
    student_answers.append([1,2,3,4,5]) # 1๋ฒˆ ํ•™์ƒ
    student_answers.append([2,1,2,3,2,4,2,5]) # 2๋ฒˆ ํ•™์ƒ
    student_answers.append([3,3,1,1,2,2,4,4,5,5]) # 3๋ฒˆ ํ•™์ƒ
    
    # 1๋ฒˆ, 2๋ฒˆ, 3๋ฒˆ ํ•™์ƒ์˜ ์ •๋‹ต ๊ฐœ์ˆ˜
    count = [0,0,0]
    
    # ๊ฐ ํ•™์ƒ์— ๋Œ€ํ•ด์„œ, ํ•˜๋‚˜์”ฉ ์ •๋‹ต์„ ํ™•์ธํ•˜๋ฉฐ ๋งž์ถ˜ ๊ฐœ์ˆ˜๋ฅผ ์นด์šดํŠธ
    for i in range(3):
        for j in range(len(answers)):
            # ๊ฐ ๋ฌธ์ œ์˜ ๋ฒˆํ˜ธ๋ฅผ ํ•™์ƒ์˜ ๋‹ต์•ˆ์ง€์˜ ๊ธธ์ด๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๋ฅผ ์ธ๋ฑ์Šค๋กœ ์ด์šฉ
            if student_answers[i][j%len(student_answers[i])] == answers[j]:
                count[i] += 1
            
    # ๊ฐ€์žฅ ๋งŽ์ด ๋งž์ถ˜ ํ•™์ƒ๋“ค์˜ ๋ฒˆํ˜ธ๋ฅผ ๋ฐ˜ํ™˜
    answer = []
    for i in range(3):
        if count[i] == max(count):
            answer.append(i + 1)
    
    return answer
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€