Programmers 87

[Kotlin] Programmers Lv. 2 튜플

https://school.programmers.co.kr/learn/courses/30/lessons/118667 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 Code import java.util.LinkedList import java.util.Queue fun main() { println(solution(intArrayOf(2,3,7,2), intArrayOf(4,6,5,1))) } fun solution(queue1: IntArray, queue2: IntArray): Int { var answer: Int = 0 val size = q..

Programmers/Lv. 2 2023.03.25

[Kotlin] Programmers 코딩테스트 입문 Day 14 조건문, 반복문, 시뮬레이션, 문자열

가까운 수 import kotlin.math.absoluteValue class Solution { fun solution(array: IntArray, n: Int) = array.sorted().minWithOrNull(compareBy { (it - n).absoluteValue })!! } 369게임 class Solution { fun solution(order: Int) = order.toString().count { it == '3' || it == '6' || it == '9' } } 암호 해독 class Solution { fun solution(cipher: String, code: Int): String { var answer: String = "" for (i in code-1 un..

[Kotlin] Programmers 코딩테스트 입문 Day 13 문자열, 배열, 사칙연산, 수학, 조건문

컨트롤 제트 class Solution { fun solution(s: String): Int { var answer: Int = 0 var str = s.split(" ") for (i in 0 until str.size){ if (str[i].equals("Z")) answer -= str[i-1].toInt() else answer += str[i].toInt() } return answer } } 배열 원소의 길이 class Solution { fun solution(strlist: Array) = strlist.map { it.length } } 중복된 문자 제거 class Solution { fun solution(my_string: String) = my_string.toSet().joinT..

[Kotlin] Programmers Lv. 2 거리두기 확인하기

https://school.programmers.co.kr/learn/courses/30/lessons/81302 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 Code class Solution { fun solution(places: Array): IntArray { var answer: IntArray = intArrayOf() for (place in places){ val room = arrayOf(place[0].split(""), place[1].split(""),place[2].split(""),place[3].split(""),pla..

Programmers/Lv. 2 2023.03.23

[Kotlin] Programmers 코딩테스트 입문 Day 12 문자열, 정렬, 사칙연산, 수학

모음 제거 class Solution { fun solution(my_string: String) = my_string.replace("a|e|i|o|u".toRegex(), "") } 문자열 정렬하기(1) class Solution { fun solution(my_string: String) = my_string.replace("[^\\d]".toRegex(), "").toList().sorted().map { it - '0' } } 숨어있는 숫자의 덧셈(1) class Solution { fun solution(my_string: String) = my_string.replace("[^\\d]".toRegex(), "").map {it - '0'}.sumOf { it } } 소인수분해 class So..

[Kotlin] Programmers 코딩테스트 입문 Day 11 수학, 반복문

주사위의 개수 class Solution { fun solution(box: IntArray, n: Int) = (box[0]/n) * (box[1]/n) * (box[2]/n) } 합성수 찾기 class Solution { fun solution(n: Int) = n - countPrimes(n) fun countPrimes(size: Int): Int{ var count = 0 for (i in 1..size) { if (miniCount(i)) count++ } return count } fun miniCount(n: Int): Boolean{ for (j in 2 until n) if (n % j == 0) return false return true } } 최댓값 만들기(1) class Solu..

[Kotlin] Programmers 코딩테스트 입문 Day 10 조건문, 배열, 수학, 시뮬레이션

점의 위치 구하기 class Solution { fun solution(dot: IntArray) = if (dot[0] > 0){ if (dot[1] > 0){ 1 }else 4 }else{ if (dot[1] > 0) 2 else 3 } } 2차원으로 만들기 class Solution { fun solution(num_list: IntArray, n: Int)= num_list.toList().chunked(n) } 공 던지기 class Solution { fun solution(numbers: IntArray, k: Int) = numbers[((k-1)*2)%numbers.size] } 배열 회전시키기 class Solution { fun solution(numbers: IntArray, dire..

[Kotlin] Programmers Lv. 2 주차 요금 계산

https://school.programmers.co.kr/learn/courses/30/lessons/92341 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 Code fun solution(fees: IntArray, records: Array): IntArray { var answer: MutableMap = mutableMapOf() // fees : 기본시간, 기본요금, 단위시간, 단위요금 // => defaultFee + (총 소요시간 - defaultTime)올림 * unitFee val defaultTime = fees[0] val d..

Programmers/Lv. 2 2023.03.20

[Kotlin] Programmers 코딩테스트 입문 Day 09 수학, 문자열, 해시, 완전탐색, 조건문

개미 군단 class Solution { fun solution(hp: Int) = hp/5 + (hp%5)/3 + (hp%5%3) } 모스부호(1) class Solution { fun solution(letter: String): String { var result: String = "" val morse = mapOf( ".-" to "a", "-..." to "b","-.-." to "c","-.." to "d","." to "e","..-." to "f", "--." to "g","...." to "h", ".." to "i",".---" to "j","-.-" to "k",".-.." to "l", "--" to "m","-." to "n","---" to "o", ".--." to "p","..

[Kotlin] Programmers 코딩테스트 입문 Day 08 배열, 구현, 수학

배열 자르기 class Solution { fun solution(numbers: IntArray, num1: Int, num2: Int): IntArray = numbers.sliceArray(num1..num2) } 외계행성의 나이 class Solution { fun solution(age: Int) = age.toString().map { it+49 }.joinToString("") } 진료순서 정하기 class Solution { fun solution(emergency: IntArray) = emergency.map { emergency.sortedDescending().indexOf(it) + 1 }.toIntArray() } 순서쌍의 개수 class Solution { fun solutio..