4 kyu
Text align justify
212 of 8,523kesheshyan
Description:
Your task in this Kata is to emulate text justification in monospace font. You will be given a single-lined text and the expected justification width. The longest word will never be greater than this width.
Here are the rules:
- Use spaces to fill in the gaps between words.
- Each line should contain as many words as possible.
- Use '\n' to separate lines.
- Last line should not terminate in '\n'
- '\n' is not included in the length of a line.
- Gaps between words can't differ by more than one space.
- Lines should end with a word not a space.
- Large gaps go first, then smaller ones ('Lorem--ipsum--dolor--sit-amet,' (2, 2, 2, 1 spaces)).
- Last line should not be justified, use only one space between words.
- Lines with one word do not need gaps ('somelongword\n').
Example with width=30:
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Vestibulum sagittis dolor
mauris, at elementum ligula
tempor eget. In quis rhoncus
nunc, at aliquet orci. Fusce
at dolor sit amet felis
suscipit tristique. Nam a
imperdiet tellus. Nulla eu
vestibulum urna. Vivamus
tincidunt suscipit enim, nec
ultrices nisi volutpat ac.
Maecenas sit amet lacinia
arcu, non dictum justo. Donec
sed quam vel risus faucibus
euismod. Suspendisse rhoncus
rhoncus felis at fermentum.
Donec lorem magna, ultricies a
nunc sit amet, blandit
fringilla nunc. In vestibulum
velit ac felis rhoncus
pellentesque. Mauris at tellus
enim. Aliquam eleifend tempus
dapibus. Pellentesque commodo,
nisi sit amet hendrerit
fringilla, ante odio porta
lacus, ut elementum justo
nulla et dolor.
Also you can always take a look at how justification works in your text editor or directly in HTML (css: text-align: justify).
Have fun :)
Strings
Algorithms
Similar Kata:
Stats:
Created | May 22, 2014 |
Published | May 22, 2014 |
Warriors Trained | 43329 |
Total Skips | 14209 |
Total Code Submissions | 168179 |
Total Times Completed | 8523 |
JavaScript Completions | 3126 |
CoffeeScript Completions | 48 |
Python Completions | 3366 |
Haskell Completions | 243 |
Ruby Completions | 532 |
C# Completions | 645 |
PHP Completions | 212 |
Java Completions | 472 |
Scala Completions | 27 |
Total Stars | 1475 |
% of votes with a positive feedback rating | 89% of 1151 |
Total "Very Satisfied" Votes | 957 |
Total "Somewhat Satisfied" Votes | 144 |
Total "Not Satisfied" Votes | 50 |