将消息分成像SMS中的块并查找消息长度限制

时间:2015-11-16 09:29:27

标签: python algorithm

我正在尝试将一条消息拆分成块,并在不删除任何单词的情况下注释这些块。这些块具有与之关联的字符限制

例如,使用char限制20

输入:

"Hi there Mr. Programmer!"

输出:

["Hi there Mr.(1/2)", "Programmer!(2/2)"]

我无法确定消息长度的限制。消息长度有一个限制,因为消息的长度可能导致块超出字符限制。

例如:

"Hey Bobby! There is a ball in the park today"

如果我将字符数限制设置为11,我就会遇到字符限制不够的问题。

"Hey(1/10)"    9 = 3 + 6
"Bobby(2/10)"  11 = 5 + 6
"!(3/10)"      7
"There(4/10)"  11
"is a(5/10)"   10
"ball(6/10)"   10
"in(7/10)"     8
"the(8/10)"    9
"park(9/10)"   10
"today(10/10)" 12 = 5 + 7 --> over char limit!

0 个答案:

没有答案