[백준] Lunacy (4714)(kotlin)

문제 설명Permalink

백준 4714번 문제 링크

입력 및 출력Permalink

» 입력Permalink

Input consists of one or more lines, each containing a single floating point number denoting a weight (in pounds) on the Earth. The end of input is denoted by a negative floating point number.

» 출력Permalink

  • For each line of input data, your program should print a single line of the form Objects weighing X on Earth will weigh Y on the moon. where X is the weight from the input and Y is the corresponding weight on the moon. Both output numbers should be printed to a precision of 2 digits after the decimal point.

예제 입출력(테스트케이스)Permalink

입력 출력
100.0
12.0
0.12
120000.0
-1.0
Objects weighing 100.00 on Earth will weigh 16.70 on the moon.
Objects weighing 12.00 on Earth will weigh 2.00 on the moon.
Objects weighing 0.12 on Earth will weigh 0.02 on the moon.
Objects weighing 120000.00 on Earth will weigh 20040.00 on the moon.

문제 풀이1Permalink

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

fun main(args: Array<String>) = with(BufferedReader(InputStreamReader(System.`in`))) {
    while(true) {
        val weigh = readLine().toFloat()
        if (weigh == -1.0f) break

        println("Objects weighing "
                + "%.02f".format(weigh)
                + " on Earth will weigh "
                + "%.02f".format(weigh * 0.167f)
                + " on the moon.")
    }
}