在狭窄的空间中打印长句子 [英] to print long sentence in narrow space

查看:104
本文介绍了在狭窄的空间中打印长句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我的问题是如何在狭窄的空间中打印长句子的算法
每个单词都不能拆分.例如:

句子是你好,我现在住在伦敦"

借用空间宽度仅适用于生活"一词
但是句子可能会打印多行

所以打印出来的是:

你好
全部
我是
生活

伦敦

谢谢
hanf

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:

Hello
all
I am
living
in
London

thank you
hanf

推荐答案

计算空间的宽度和句子的宽度.每次重新计算宽度时,您都可以从此处将句子分成更小的部分,直到所有部分都适合为止.
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.


这篇关于在狭窄的空间中打印长句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆