文字列の均等分割
この問題は、除算だけでははく算術演算とか、文字列の長さをstrlenの類いで測るとかをしなくても、多分書けるのではないかと思います。
Posted feedbacks - HSP
ジュースを複数のグラスに注ぎ分ける時と同じような考え方です。 投稿間際に確認したところ、ところてん さんと同じ手法のようですね。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // 入力される値が2byte文字のみと仮定
#module
#deffunc divid str _target, int num
if (num <= 0) : return
target = _target
dim result, num
count = 0
repeat strlen(target) >> 1
result(count) += 2
count++
if(count == num) : count = 0
loop
count = 0
repeat num
mes strmid(target, count, result(cnt))
count += result(cnt)
loop
return
#global
sample = "ゆめよりもはかなき世のなかをなげきわびつゝあかしくらすほどに四月十よひにもなりぬれば木のしたくらがりもてゆく"
divid sample, 4
divid sample, 5
divid sample, 6
|




nobsun
#4090()
Rating-1/3=-0.33
1 reply [ reply ]