[백준] Speed Limit (4635)(kotlin)

문제 설명

백준 4635번 문제 링크

입력 및 출력

» 입력

The input consists of one or more data sets. Each set starts with a line containing an integer n, 1 ≤ n ≤ 10, followed by n pairs of values, one pair per line. The first value in a pair, s, is the speed in miles per hour and the second value, t, is the total elapsed time. Both s and t are integers, 1 ≤ s ≤ 90 and 1 ≤ t ≤ 12. The values for t are always in strictly increasing order. A value of -1 for n signals the end of the input.

» 출력

For each input set, print the distance driven, followed by a space, followed by the word “miles”.

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

입력 출력
3
20 2
30 6
10 7
2
60 1
30 5
4
15 1
25 2
30 3
10 5
-1
170 miles
180 miles
90 miles

문제 풀이1

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

fun main(args: Array<String>) = with(BufferedReader(InputStreamReader(System.`in`))) {
    while (true) {
        val cases = readLine().toInt()
        if (cases == -1) break

        var miles = 0
        var hours = 0

        repeat(cases) {
            val (mph, eth) = readLine().split(" ").map { it.toInt() }
            miles += (mph * (eth - hours))
            hours = eth
        }

        println("$miles miles")
    }
}