[백준] A+B (1000)(Kotlin)

[백준] A+B

원본 문제

문제 풀이1

import java.io.BufferedReader
import java.io.InputStreamReader

fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {

    val (a: Int, b: Int) = readLine()
        .split(" ")
        .map { it.toInt() }

    println(a + b)

}

문제 풀이2

import java.io.BufferedReader
import java.io.InputStreamReader

fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {

    println(
        readLine()
        .split(" ")
        .map { it.toInt() }
        .fold(0, { total, next -> total + next })
    )

}

문제 풀이3

import java.io.BufferedReader
import java.io.InputStreamReader

fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {

    println(
        readLine()
            .split(" ")
            .map { it.toInt() }
            .reduce{ total, next -> total + next }
    )

}

문제 풀이4

import java.io.BufferedReader
import java.io.InputStreamReader

fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {

    println(
        readLine()
            .split(" ")
            .map { it.toInt() }
            .sumBy { it }
    )

}

문제 풀이5

import java.io.BufferedReader
import java.io.InputStreamReader

fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {

    println(
        readLine()
            .split(" ")
            .map { it.toInt() }
            .sum()
    )

}

카테고리:

업데이트: