Algorithm, Problem Solving/codeforces

[codeforces][Kotlin] 313A - Ilya and Bank Account

태오님 2023. 3. 27.

목차

     

    문제 정보

    https://codeforces.com/problemset/problem/313/A

     

    Problem - 313A - Codeforces

     

    codeforces.com

    난이도 : A

    유형 : Math


    문제 풀이

    • 입력값이 양수) 
      • 입력값 자체가 정답
    • 입력값이 음수)
      • 자릿수가 1개라면 정답은 0
      • 그 외인 경우 첫 번째 자리를 뺀 수 vs 두 번째 자리를 뺀 수 중 더 큰 값이 정답

    코드

    import java.io.BufferedReader
    import java.io.InputStreamReader
    
    fun solution() = with(BufferedReader(InputStreamReader(System.`in`))) {
        var input = readLine().toInt()
        if (input < 0) {
            if (input >= -10) {
                input = 0
            } else {
                input = (input / 10).coerceAtLeast(input / 100 * 10 + (input % 10))
            }
        }
    
        println(input)
    }
    
    fun main() {
        solution()
    }

    댓글