当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3218:Alignments

题目描述

HTML supports four different text alignments: left, right, center and justify. Compare the following examples:

AlignmentExample
LeftMany 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.
Right

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.

Center

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. 

JustifyMany  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.

Text-based browsers render aligned texts by inserting spaces between neighboring words. Here words are strings consisting of non-space characters.

Now you are to implement a small routine that simulates the text-browsers’ behaviors in rendering aligned texts specified in the table below:

AlignmentRenderingSpacing
LeftText lines are rendered flush left.Single spaces separate neighboring words.
RightText lines are rendered flush right.
CenterText lines are centered.Single spaces separate neighboring words. Spaces before the first word should be no more and at most one less than those after the last word.
JustifyText lines are justified to both margins except the last one and those that contain a single word, which are aligned left.Special spacing is considered for lines that are not required to be aligned left. Multiple spaces may separate neighboring words. For any two “gaps” between words, the one on the left should be no narrower and at most one space wider than the one on the right.

Your routine works in a greedy manner, that is, as many as possible words should be put into the first line, then as many as possible words should be put into the second line, etc.. Line width is fixed in your routine to be 75 characters.

输入解释

The input contains a single test case on multiple lines. The first line contains only one character among “L”, “R”, “C” and “J”, which means some text is to be aligned left, right, centered or justified. Words of the text are found on the following at most five lines. Those on the same line are separated by at least one spaces. They will only contain characters with ASCII code between 33 and 126 (inclusive) and are less than 75 characters long.

输出解释

Just print out the rendered text produced by your routine.

输入样例
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.
提示

Trailing spaces at the end of each output line can be ignored, though keeping them is also acceptable.


该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3218

最后修改于 2020-10-29T06:56:07+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 131072