programmers 91

[Kotlin] Programmers 코딩테스트 입문 Day 18 문자열, 수학, 조건문, 정렬

문자열안에 문자열 class Solution { fun solution(str1: String, str2: String): Int = if (str1.contains(str2)) 1 else 2 } 제곱수 판별하기 import kotlin.math.sqrt class Solution { fun solution(n: Int) = if(sqrt(n.toDouble())%1 == 0.0) 1 else 2 } 세균 증식 class Solution { fun solution(n: Int, t: Int): Int { var result = n for (i in 1..t) result *=2 return result } } 문자열 정렬하기 (2) class Solution { fun solution(my_string..

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

숫자 찾기 class Solution { fun solution(num: Int, k: Int) = "-$num".indexOf(k.toString()) } n의 배수 고르기 class Solution { fun solution(n: Int, numlist: IntArray) = numlist.filter { it % n == 0 } } 자릿수 더하기 class Solution { fun solution(n: Int): Int { var length = n.toString() var sum: Int = 0 for (i in length) { sum += i.toInt() -48 } return sum } } OX퀴즈 class Solution { fun solution(quiz: Array): Array..

[Kotlin] Programmers 코딩테스트 입문 Day 16 문자열, 수학, 배열, 조건문

편지 class Solution { fun solution(message: String) = message.length * 2 } 가장 큰 수 찾기 class Solution { fun solution(array: IntArray): IntArray = intArrayOf(array.maxOrNull()!!,array.indexOf(array.maxOrNull()!!)) } 문자열 계산하기 class Solution { fun solution(my_string: String): Int { val result = my_string.split(" ") var answer = result[0].toInt() for (i in 1 until result.size step(2)){ if (result[i] == ..

[Kotlin] Programmers 코딩테스트 입문 Day 15 문자열, 해시, 배열, 수학

영어가 싫어요 class Solution { fun solution(numbers: String): Long{ var answer = numbers val number = mapOf( "one" to "1", "two" to "2", "three" to "3", "four" to "4", "five" to "5", "six" to "6", "seven" to "7", "eight" to "8", "nine" to "9", "zero" to "0" ) for (i in number){ answer = answer.replace(i.key, i.value) } return answer.toLong() } } 인덱스 바꾸기 class Solution { fun solution(my_string: String,..

[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..