728x90
개미 군단
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<String,String>(
".-" 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","--.-" to "q",".-." to "r",
"..." to "s", "-" to "t", "..-" to "u", "...-" to "v", ".--" to "w","-..-" to "x",
"-.--" to "y","--.." to "z"
)
var temp = letter.split(" ")
for (i in temp)
result += morse.get(i)
return result
}
}
가위 바위 보
class Solution {
fun solution(rsp: String): String = rsp.map{
when(it){
'2' -> '0'
'0' -> '5'
else -> '2'
}
}.joinToString("")
}
구슬을 나누는 경우의 수
import java.math.BigInteger
class Solution {
fun solution(balls: Int, share: Int): BigInteger = (factorial(balls)) / ((factorial(balls - share) * factorial(share)))
fun factorial(time: Int): BigInteger {
var result: BigInteger = BigInteger("1")
for (i in 2..time) result = result * i.toBigInteger()
return result
}
}
728x90