[Programmers] ๋ชจ์˜๊ณ ์‚ฌ

Updated:

๋ชจ์˜๊ณ ์‚ฌ

๋ชจ์˜๊ณ ์‚ฌ ๋ฅผ ํด๋ฆญํ•˜๋ฉด ๋ฐ”๋กœ ์ด๋™ํ•œ๋‹ค.

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์—์„œ ์ œ๊ณตํ•˜๋Š” ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๊ธฐ์ถœ๋ฌธ์ œ์ค‘ Level 1 ๋ฌธ์ œ๋Š” ๋‹ค ํ’€์–ด์„œ Level 2 ๋ฅผ ํ’€๊ธฐ ์ „์—

์ผ๋‹จ ๊ธฐ์ดˆ ํŠผํŠผ Level 1 ๋ฌธ์ œ๋ฅผ ์ „๋ถ€ ํ’€๊ณ  ๊ฐ€๋ ค๊ณ  ํ•œ๋‹ค.

๊ทธ ์ค‘ ์ฒซ ๋ฒˆ์งธ๋Š” ์™„์ „ํƒ์ƒ‰์„ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ์˜๊ณ ์‚ฌ ๋ฌธ์ œ.

def check_answer(answers, checkList, checkCnt):

	for index,value in enumerate(answers):
		if checkList[index % len(checkList)] == value:
			checkCnt += 1
	return checkCnt

def solution(answers):
	answer = []
	answerCnt = []

	one = [1, 2, 3, 4, 5]
	two = [2, 1, 2, 3, 2, 4, 2, 5]
	three = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]

	oneCnt = twoCnt = threeCnt = 0
	answerCnt.append(check_answer(answers, one, oneCnt))
	answerCnt.append(check_answer(answers, two, twoCnt))
	answerCnt.append(check_answer(answers, three, threeCnt))

	for index, value in enumerate(answerCnt):
		if max(answerCnt) == value:
			answer.append(index+1)

	return answer

Level 2 ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ ์ „์— ๊ฐœ๋…์„ ๋” ํŠผํŠผํžˆ ํ•˜๊ณ  ์ฝ”๋“œ๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์„ ์ˆ˜์ค€์œผ๋กœ ์˜ฌ๋ฆฐ ๋’ค์— ๋‹ค๋ฅธ ์‘์šฉ๋ฌธ์ œ๋ฅผ ํ’€์–ด์•ผ ๊ฒ ๋‹ค.


Categories:

Updated:

Leave a comment