文字列と整数nが与えられた場合、その文字列をn文字で分割し、次のように出力します。 例)
laptop 3
should print lap top
laptop 2
should print la pt op
(see
how it splits the string at every 2nd char)
特殊なケース:
laptop 0
should print laptop
(since we
split at every 0th char, thus none)
laptop 9
should print laptop
(since
length of laptop < 9, so no splitting)
bob 2
should print bo b
(we split at
the o
(2nd char), but then there aren’t enough
characters after, so we just leave as is`
You may assume n >= 0
ベストアンサー
Japt, 7 bytes
òVªLl)¸
説明
Implicit: U, V = inputs
UòV ) Split U into slices of length V.
ªLl If V is 0, instead use 100! (roughly 9.3326e+157).
¸ Join with spaces.
Implicit: output result of last expression
9.3326e + 157は、JavaScriptの最大文字列サイズ9.0072e +
15よりもはるかに大きいので、これはどの入力でも機能します。