Programmers 87

[Kotlin] Programmers 코딩테스트 입문 Day 07 문자열, 조건문, 수학, 반복문

특정 문자 제거하기 class Solution { fun solution(my_string: String, letter: String) = my_string.replace(letter,"") }​ 각도기 class Solution { fun solution(angle: Int) = if (angle < 90) 1 else if (angle == 90) 2 else if (angle < 180) 3 else 4 } 양꼬치 class Solution { fun solution(n: Int, k: Int) = n * 12000 + ((k-n/10)*2000) } 짝수의 합 class Solution { fun solution(number: Int): Int = (0..number step 2).sum() }

[Kotlin] Programmers 코딩테스트 입문 Day 06 문자열, 반복문, 출력, 배열, 조건문

문자열 뒤집기 class Solution { fun solution(my_string: String) = my_string.reversed() } 직각삼각형 출력하기 fun main(args: Array) { val (n) = readLine()!!.split(' ').map(String::toInt) repeat(n){ for (i in 0..it){ print("*") } println() } } 짝수 홀수 개수 class Solution { fun solution(num_list: IntArray) = intArrayOf( num_list.filter { it % 2 == 0 }.count(), num_list.filter { it % 2 == 1 }.count() ) } 문자 반복 출력하기 fun..

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

옷가게 할인 받기 class Solution { fun solution(price: Int) = if(price >= 500000) (price * 0.8).toInt() else if (price >= 300000) (price * 0.9).toInt() else if (price >= 100000) (price * 0.95).toInt() else price } 아이스 아메리카노 class Solution { fun solution(money: Int) = intArrayOf(money / 5500, money % 5500) } 나이 출력 class Solution { fun solution(age: Int) = 2022 - age + 1 } 배열 뒤집기 class Solution { fun solu..

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

피자 나눠 먹기 (1) class Solution { fun solution(n: Int) = if (n%7 == 0) n/7 else n/7+1 } 피자 나눠 먹기 (2) class Solution { fun solution(n: Int) = n / gcd(n,6) tailrec fun gcd(n:Int, m:Int): Int = if (m == 0) n else gcd(m, n%m) } 피자 나눠 먹기 (3) class Solution { fun solution(slice: Int, n: Int) = if (n%slice == 0) n/slice else n/slice+1 }​ 배열의 평균값 class Solution { fun solution(number: IntArray) = number.sum(..

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

나머지 구하기 class Solution { fun solution(num1: Int, num2: Int) = num1%num2 } 중앙값 구하기 class Solution { fun solution(array: IntArray) = array.sorted()[array.size/2] } 최빈값 구하기 class Solution { fun solution(array: IntArray): Int { var count: Int = 0 var answer: Int = 0 var bool: Int = 0 var arr = Array(2000){0} for(i:Int in 0..array.size-1) { arr[array[i]+1000]++ if (arr[array[i]+1000] == count) bool++..

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

두 수의 나눗셈 class Solution { fun solution(num1: Int, num2: Int) = (num1/num2.toDouble() * 1000).toInt() } 숫자 비교하기 fun solution(num1: Int, num2: Int) = if(num1 == num2) 1 else -1 분수의 덧셈 class Solution { fun solution(numer1: Int, denom1: Int, numer2: Int, denom2: Int) = intArrayOf(numer1 * lcm(denom1,denom2)/denom1 + numer2 * lcm(denom1,denom2)/denom2, lcm(denom1,denom2)) fun gcd(num1: Int, num2: Int..