suru1206's blog

By suru1206, history, 9 days ago, In English

Given a character limit and a message, split the message up into annotated chunks without cutting words as, for example when sending the SMS

"It is an amazing experience to give tests on Doselect!!" with char limit 17, you should get

["It is an,(1/6)", "amazing(2/6)", "experience(3/6)","to give(4/6)","tests on(5/6)","Doselect!!(6/6)"]

Can anyone help me with this question in cpp?

 
 
 
 
  • Vote: I like it
  • -18
  • Vote: I do not like it

»
9 days ago, # |
  Vote: I like it +9 Vote: I do not like it

A greedy approach seems to be most optimal, no? Just add the words one by one while they fit.

  • »
    »
    9 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    And then what about whitespace i tried with one by one but it is taking some half words like "It is an amazing","experience to giv","etest on DoSelect"...like this

    • »
      »
      »
      8 days ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      If a word would be cut in half just don't add it, start a new message instead. It's optimal.