Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- dp
- solution
- 코틀린
- 프로그래머스
- 2020
- GREEDY
- Util
- 알고리즘
- Recursion
- Kotlin
- heap
- Main
- programmers
- PriorityQueue
- lastIndex
- sortedBy
- report
- Queue
- Java
- 동적계획법
- contentToString
- dynamic programming
- Poll
- hackerrank
- booleanarray
- Developer
- foreach
- 2D Array
- indices
- intarray
Archives
- Today
- Total
Code in
프로그래머스 완전탐색 모의고사 with Kotlin 본문
프로그래머스 완전탐색 부분 모의고사 문제입니다.
IntelliJ에서의 문제 풀이입니다.
val operations: IntArray = intArrayOf(1, 3, 2, 4, 2)
fun solution(answers: IntArray): IntArray {
var answer = intArrayOf()
var a: Int = 0 // 맞은 개수 count
var b: Int = 0
var c: Int = 0
val aa: IntArray = intArrayOf(1, 2, 3, 4, 5) // 답안지
val bb: IntArray = intArrayOf(2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5)
val cc: IntArray = intArrayOf(3, 3, 1, 1, 2, 2, 4, 4, 5, 5)
var cnt = 0
answers.forEach {
if (it == aa[ cnt % aa.size ]) a++ // 답안지의 답과 비교
if (it == bb[ cnt % bb.size ]) b++
if (it == cc[ cnt % cc.size ]) c++
cnt++
}
if (a >= b && a >= c) answer += 1 // 순서대로 최고점일 경우 추가
if (b >= a && b >= c) answer += 2
if (c >= b && c >= a) answer += 3
return answer
}
fun main() {
print(solution(operations).contentToString()) // 1, 2, 3
}
URL: https://programmers.co.kr/learn/courses/30/lessons/42840
코딩테스트 연습 - 모의고사
수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는 ��
programmers.co.kr
'알고리즘 스터디_문제풀이' 카테고리의 다른 글
프로그래머스 완전탐색 카펫 with Kotlin (1) | 2020.08.14 |
---|---|
프로그래머스 완전탐색 소수 찾기 with Kotlin (1) | 2020.08.14 |
프로그래머스 힙 이중우선순위큐 with Kotlin (0) | 2020.08.12 |
프로그래머스 힙 디스크 컨트롤러 with Kotlin (0) | 2020.08.12 |
프로그래머스 큐 프린터 with Kotlin (0) | 2020.08.11 |
Comments