17: Text Typesetting
Describe
For an English essay, the words are separated by a space (each word includes a punctuation mark immediately before and after it). Please re-layout the passage, the following requirements:
No more than 80 characters per line, each word on the same line, separated by a space between words on the same line, and no spaces at the beginning or end of the line.
The first line of input is an integer n, which indicates the number of words in the English essay. The following is a space-delimited list of English words (the word includes the punctuation immediately before and after it, and the length of each word is no greater than 40 letters). Outputs the formatted multiline text with a maximum of 80 characters per line of text characters, separated by a space, with no spaces for each line of text. Sample input
Sample output
One sweltering day, I is scooping ice cream into cones and told my fourchildren they could "buy" a cone from me for a hug . Almost immediately, the kidslined up and make their purchases. The three youngest each gave me a quick hug,grabbed their cones and raced back outside. But if my teenage son at the endof of the line finally got his turn to "buy" his ice cream, he gave me and hugs. " Keep the changes, "he said with a smile.
1#include <cstdio>2#include <cstring>3 using namespacestd;4 Charm[ -];5 intn,tot,x;6 intMain ()7 {8scanf"%d",&n);9 while(++x<=N)Ten { Onescanf"%s", m); Atot+=strlen (m); - if(tot!= the) tot++; - if(tot> the) the { -printf"\ n"); -Tot=strlen (m) +1; - } +printf"%s", m); - if(tot!= the&&x!=n) printf (" "); +Memset (M,0,sizeof(m)); A } at return 0; -}
1.13.17