problem The objective is to build a program that receives a text and formats it in such a way that the text is divided into lines that do not exceed a given size n. In other words, each output line must have a length less than or equal to n, must respect the original order of the words, must include the maximum number of words possible per line, and must include only complete words separated by a space.   Entry A line that contains the text to be divided and an integer n that corresponds to the maximum size of characters per line. n will always be greater than or equal to the size of the longest word in the text plus one. Words in the input text will be separated by one or more blank spaces. Departure

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 21PE
icon
Related questions
Question

Python problem

The objective is to build a program that receives a text and formats it in such a way that the text is divided into lines that do not exceed a given size n. In other words, each output line must have a length less than or equal to n, must respect the original order of the words, must include the maximum number of words possible per line, and must include only complete words separated by a space.

 


Entry
A line that contains the text to be divided and an integer n that corresponds to the maximum size of characters per line. n will always be greater than or equal to the size of the longest word in the text plus one. Words in the input text will be separated by one or more blank spaces.


Departure
The first and last lines must contain a space, n characters "*" and another space at the end. Lines in the requested format must begin and end with the "|" character. The line must be completed before the "|" with spaces


Examples

Input Example 1

In Sumatra, someone wants to get a doctorate as a fortune teller. The examining witch asks him if he will be failed or if he will pass. The candidate responds that he will be failed.
twenty
Output Example 1

********************
| In Sumatra, someone |
| wants to get a doctorate from |
| I guess. The witcher |
| examiner him |
| ask if he will be |
| failed or if |
| will pass. The candidate |
| answer that it will be |
| failed. |
********************

Input Example 2

In Sumatra, someone wants to get a doctorate as a fortune teller. The examining sorcerer asks him if he will be failed or if he will pass. The candidate responds that he will be failed.
eleven
Output Example 2

***********
| In Sumatra, |
| someone |
| wants |
| get a doctorate |
| as a fortune teller. |
| The witcher |
| examiner |
| asks him |
| if it will be |
| failed or |
| if it will happen. |
| The |
| candidate |
| answer |
| what will be |
| failed. |
***********

Notes
The output must have a new line character at the end otherwise you may receive the wrong answer verdict.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning