mirror of
https://gitlab.com/mfocko/Codeforces.git
synced 2024-12-21 13:41:22 +01:00
1157(A,kt): solve “Reachable Numbers”
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
54ade11dd9
commit
3ad2018645
2 changed files with 1392 additions and 0 deletions
23
1157/A.kt
Normal file
23
1157/A.kt
Normal file
|
@ -0,0 +1,23 @@
|
|||
//import readInt
|
||||
|
||||
fun removeTrailingZeros(n: Int): Int =
|
||||
if (n % 10 == 0)
|
||||
removeTrailingZeros(n / 10)
|
||||
else
|
||||
n
|
||||
|
||||
fun f(n: Int): Int = removeTrailingZeros(n + 1)
|
||||
|
||||
fun findReachable(n: Int): Int {
|
||||
val reachable = mutableSetOf<Int>()
|
||||
var m = n
|
||||
|
||||
while (reachable.add(m)) m = f(m)
|
||||
|
||||
return reachable.size
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val n = readLine()!!.toInt()
|
||||
println(findReachable(n))
|
||||
}
|
1369
1157/index.html
Normal file
1369
1157/index.html
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue