#P3218. Alignments

Alignments

Description

HTML支持四种文本对齐方式:左对齐、右对齐、居中和两边对齐。比较下面的例子:

对齐方式例子
左对齐Many years later, as he faced the firing squad, Colonel Aureliano Buendia
was to remember that distant afternoon when his father took him to discover
ice.
右对齐

Many years later, as he faced the firing squad, Colonel Aureliano Buendia
was to remember that distant afternoon when his father took him to discover
ice.

居中

Many years later, as he faced the firing squad, Colonel Aureliano Buendia
was to remember that distant afternoon when his father took him to discover
 ice.

两边对齐Many  years  later, as he faced the firing squad, Colonel Aureliano Buendia
was to remember that distant afternoon when his father took him to discover
ice.

文本模式浏览器通过在相邻单词之间插入空格来显示对齐文本。在这里,但此就是由不是空格的字符组成的字符串。

现在你要来实现一个小程序来按下表指定的方式模仿文本模式浏览器在显示对齐文本时的行为。

对齐方式显示效果空格
左对齐文本靠左显示。相邻单词间用一个空格分隔。
右对齐文本靠右显示。
居中文本居中显示。相邻单词间用一个空格分隔。每行第一个单词前的空格数不能多于最后一个单词后的空格数,同时前者最多比后者少1。
两边对齐文本对齐到行的两段边界。只包含一个单词的行和最后一行左对齐。不要求左对齐的行有一个特殊的方式来插入空格。相邻的单词之间可以有多个空格。对于同一行上两个“空隙”来说,左边不能比右边的窄,同时又不能比右边多2个或以上的空格。

你的程序用贪心的方式工作,也就是说,尽量多的单词应该被放入第一行,然后尽量多的单词应该被放入第二行,如此类推。行的宽度在你的程序里固定为75个字符。

Input

输入只包含一组占据多行的测试数据。第一行包含“L”、“R”、“C”和“J”之中的一个字母,分别代表一些文本要被左对齐、右对齐、居中或两边对齐显示。文本的单词在接下来最多五行中。同一行中的单词至少被一个空格分隔。单词只包括ASCII代码在33和126之间的字符,长度小于75个字符。

Output

输出你的小程序产生的对齐显示后的文字。

J
Many years later, as he faced the firing squad, Colonel Aureliano Buendia was to remember 
that distant afternoon when his father took him to discover ice.
Many  years  later, as he faced the firing squad, Colonel Aureliano Buendia
was to remember that distant afternoon when his father took him to discover
ice.

Source

第六届北京大学程序设计大赛暨ACM/ICPC选拔赛

, frkstyc

Translator

Yingchong SITU 'frkstyc'