about | help | code help+videos | done | prefs |
Text Wrap Problem 08 Worth 4 Points You are tasked with writing a program that takes a text document as input, and reformats the document so the lines are of reasonable length. Specifically, you will find good places to insert line breaks (\n character) to make the optimal line lengths. For example, given the input: You are tasked with writing a program that takes a text document as input, and reformats the document so the lines are of reasonable length. Your program will output: You are tasked with writing a program that takes a text document as input, and reformats the document so the lines are of reasonable length. Follow these simple rules: A line must not be longer than 80 characters before a line break occurs A line break (\n) may only be inserted at an existing word break, as denoted by a space character (). In other words, do not add a line break in the middle of a word! Note: Because CodingBat does not support /n characters in test cases, instead insert # signs where there should be a newline character. HPCW2020_08_TextWrap("The scenery of Walden is on a humble scale, and, though very beautiful, does not approach to grandeur, nor can it much concern one who has not long frequented it or lived by its shore; yet this pond is so remarkable for its depth and purity as to merit a particular description.") → "The scenery of Walden is on a humble scale, and, though very beautiful, does not#approach to grandeur, nor can it much concern one who has not long frequented it#or lived by its shore; yet this pond is so remarkable for its depth and purity#as to merit a particular description." HPCW2020_08_TextWrap("I find it wholesome to be alone the greater part of the time. To be in company, even with the best, is soon wearisome and dissipating. I love to be alone. I never found the companion that was so companionable as solitude. We are for the most part more lonely when we go abroad among men than when we stay in our chambers.") → "I find it wholesome to be alone the greater part of the time. To be in company,#even with the best, is soon wearisome and dissipating. I love to be alone. I#never found the companion that was so companionable as solitude. We are for the#most part more lonely when we go abroad among men than when we stay in our#chambers." HPCW2020_08_TextWrap("A man thinking or working is always alone, let him be where he will. Solitude is not measured by the miles of space that intervene between a man and his fellows.") → "A man thinking or working is always alone, let him be where he will. Solitude is#not measured by the miles of space that intervene between a man and his fellows." ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy