코딩테스트/Kotlin
[백준 6749번] [Kotlin] Next in line
유노 Uknow
2023. 5. 23. 15:58
https://www.acmicpc.net/problem/6749
6749번: Next in line
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 c
www.acmicpc.net
난이도 : 브론즈 4
태그 : 구현, 수학
설명
아이가 셋 있는 가족이 있습니다.
둘째와 셋째의 나이차이가 첫째와 둘째의 나이차와 같고,
셋째와 둘째의 나이가 주어졌을 때, 첫 째의 나이를 구하는 문제입니다.
소스코드
fun main() {
val n1 = readln().toInt()
val n2 = readln().toInt()
println(2 * n2 - n1)
}
'첫째의 나이 = (둘째의 나이 - 셋째의 나이) + 둘째의 나이 = 둘째의 나이 * 2 - 셋 째의 나이' 로 구할 수 있습니다.