Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all

My question is how is algorithm to print a long sentence in a narrow space
Each word cannot be split .For example:

the sentence is "Hello all I am living in London"

the barrow space width only enaught for word "living"
but the sentence may be printed in more than one row

so the print out will be:

I am

thank you

1 solution

Calculate the width of your space and width of the sentence. From there you can break your sentence into smaller parts each time recalculating the width, until all parts will fit.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900