백준 - 1065 한수
문제
1065 한수
답
kotlin code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.*
fun main() {
q1065()
}
fun q1065() = with(Scanner(System.`in`)) {
val input = nextInt()
var result = if(input < 100) input else 99
for(i in 111 .. input) {
val ints = i.toString().toCharArray().map { Character.getNumericValue(it) }
var itSame = true
val diffStd = ints[0] - ints[1]
for(j in 1 until (ints.count() - 1)) {
val diffThis = ints[j] - ints[j + 1]
if (diffStd != diffThis) {
itSame = false
break;
}
}
if(itSame) result++
}
println(result)
}
This post is licensed under CC BY 4.0 by the author.