[백준] Next in line (6749)(kotlin)
문제 설명Permalink
You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years.
Given the ages of the youngest and middle children, what is the age of the oldest child?
입력Permalink
The input consists of two integers, each on a separate line. The first line is the age Y of the youngest child (0 ≤ Y ≤ 50). The second line is the age M of the middle child (Y ≤ M ≤ 50).
출력Permalink
The output will be the age of the oldest child.
테스트 케이스Permalink
입력 | 출력 |
---|---|
12 15 |
18 |
문제 풀이1Permalink
import java.util.Scanner
fun main(args: Array<String>) = with(Scanner(System.`in`)) {
println(
IntArray(2) { nextInt() }
.let { "${(it[1] * 2) - it[0]}" }
)
}