結果

問題 No.428 小数から逃げる夢
ユーザー nobigomu
提出日時 2018-06-08 13:50:55
言語 Kotlin
(2.1.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,683 bytes
コンパイル時間 13,496 ms
コンパイル使用メモリ 413,572 KB
最終ジャッジ日時 2024-11-14 20:27:00
合計ジャッジ時間 14,606 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.kt:1:26: error: unresolved reference: experimental
import kotlin.coroutines.experimental.buildSequence
                         ^
Main.kt:10:9: error: unresolved reference: buildSequence
        buildSequence {
        ^
Main.kt:12:17: error: unresolved reference: yield
                yield(n * D.slice(i..i).toInt())
                ^
Main.kt:15:9: error: unresolved reference: buildSequence
        buildSequence {
        ^
Main.kt:16:13: error: unresolved reference: yield
            yield(0); yieldAll(f(m)) //; yield(0)
            ^
Main.kt:16:23: error: unresolved reference: yieldAll
            yield(0); yieldAll(f(m)) //; yield(0)
                      ^
Main.kt:17:15: error: unresolved reference: buildSequence
        }.zip(buildSequence {
              ^
Main.kt:18:13: error: unresolved reference: yieldAll
            yieldAll(f(n)); yield(0) //; yield(0)
            ^
Main.kt:18:29: error: unresolved reference: yield
            yieldAll(f(n)); yield(0) //; yield(0)
                            ^
Main.kt:21:9: error: unresolved reference: buildSequence
        buildSequence {
        ^
Main.kt:24:17: error: unresolved reference: yield
                yield(add(e,c)%10); yieldAll(iter(add(e,c)/10, sq.drop(1), add))
                ^
Main.kt:24:37: error: unresolved reference: yieldAll
                yield(add(e,c)%10); yieldAll(iter(add(e,c)/10, sq.drop(1), add))
                                    ^
Main.kt:26:29: error: unresolved reference: yield
                if (c!=0) { yield(c) }
                            ^

ソースコード

diff #
プレゼンテーションモードにする

import kotlin.coroutines.experimental.buildSequence
val D = "123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
    7677787980818283848586878889909192939495969798991"
inline fun add1(e: Int, c: Int): Int = e+c
inline fun add2(e: Pair<Int,Int>, c: Int): Int = e.first+e.second+c
fun f(s: String): Sequence<Int> {
fun f(n: Int): Sequence<Int> =
buildSequence {
for (i in (D.length-1) downTo 0)
yield(n * D.slice(i..i).toInt())
}
fun g(m: Int, n: Int): Sequence<Pair<Int,Int>> =
buildSequence {
yield(0); yieldAll(f(m)) //; yield(0)
}.zip(buildSequence {
yieldAll(f(n)); yield(0) //; yield(0)
})
tailrec fun <T> iter(c: Int, sq: Sequence<T>, add: (T, Int) -> Int): Sequence<Int> =
buildSequence {
val e = sq.firstOrNull()
if (e!=null) {
yield(add(e,c)%10); yieldAll(iter(add(e,c)/10, sq.drop(1), add))
} else {
if (c!=0) { yield(c) }
}
}
return (
if (s.length==1)
iter(0, f(s.toInt()), ::add1)
else
iter(0, g(s.slice(0..0).toInt(),s.slice(1..1).toInt()), ::add2)
)
}
fun fmt(s: String) =
if (s.length!=D.length)
s.slice(0..s.length-D.length-1)+"."+s.slice(s.length-D.length..s.length-1)
else
"0."+s
fun main(args: Array<String>) {
val s = readLine()!!
println(
if (s=="100")
D.slice(0..1)+"."+D.slice(2..D.length-1)
else
fmt(f(s).fold("", fun (a,e) = e.toString()+a))
)
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0