17: Text layout, 17 text Layout

Source: Internet
Author: User

17: Text layout, 17 text Layout
17: Text Layout

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

For an English short text, words are separated by spaces (each word includes punctuation marks adjacent to each other ). Re-typeset the short text. The requirements are as follows:

Each line contains no more than 80 characters. Each word occupies the same line. Words in the same line are separated by a space. There is no space at the beginning or end of the line.

Input
The first line is an integer n, indicating the number of words in the short text. followed by n English words separated by spaces (the word includes the punctuation marks adjacent to each other, and each word cannot exceed 40 letters ).
Output
Multiple lines of text after formatting. Each line of text contains a maximum of 80 characters. Words are separated by a space. There is no space at the beginning or end of each line of text.
Sample Input
84One sweltering day, I was scooping ice cream into cones and told my four children they could "buy" a cone from me for a hug. Almost immediately, the kids lined up to make their purchases. The three youngest each gave me a quick hug, grabbed their cones and raced back outside. But when my teenage son at the end of the line finally got his turn to "buy" his ice cream, he gave me two hugs. "Keep the changes," he said with a smile. 
Sample output
One sweltering day, I was scooping ice cream into cones and told my fourchildren they cocould "buy" a cone from me for a hug. almost immediately, the kidslined up to make their purchases. the three youngest each gave me a quick hug, grabbed their cones and raced back outside. but when my teenage son at the endof the line finally got his turn to "buy" his ice cream, he gave me two hugs. "Keep the changes," he said with a smile.


It indicates that the compiling environment for linux and windows is different,
The format in dev is incorrect, but the full score is in noi ,,,,
This is embarrassing ,,

1 # include <iostream> 2 using namespace std; 3 string kong; 4 string a [1001]; // save each word 5 int tot = 1; // number of rows 6 int main () 7 {8 int n; 9 cin> n; 10 for (int I = 1; I <= n; I ++) 11 {12 cin> a [I]; 13 a [I] = a [I] + ''; 14} 15 string ans; 16 for (int I = 1; I <= n; I ++) 17 {18 if (ans. length () + a [I]. length ()-2)> = 80) 19 {20 if (ans. empty () = true) 21 continue; 22 cout <ans; 23 cout <endl; 24 ans = kong; 25 ans = ans + a [I]; 26 tot ++; 27} 28 else29 {30 ans = ans + a [I]; 31} 32} 33 cout <ans; 34 return 0; 35}View Code

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.