前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >17:文字排版

17:文字排版

作者头像
attack
发布2018-04-11 11:39:58
1.4K0
发布2018-04-11 11:39:58
举报

17:文字排版

总时间限制: 1000ms 内存限制: 65536kB描述

给一段英文短文,单词之间以空格分隔(每个单词包括其前后紧邻的标点符号)。请将短文重新排版,要求如下:

每行不超过80个字符;每个单词居于同一行上;在同一行的单词之间以一个空格分隔;行首和行尾都没有空格。

输入第一行是一个整数n,表示英文短文中单词的数目. 其后是n个以空格分隔的英文单词(单词包括其前后紧邻的标点符号,且每个单词长度都不大于40个字母)。输出排版后的多行文本,每行文本字符数最多80个字符,单词之间以一个空格分隔,每行文本首尾都没有空格。样例输入

代码语言:javascript
复制
84
One 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. 

样例输出

代码语言:javascript
复制
One 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.


表示linux和windows的编译环境不一样,
在dev里格式错误但到了noi里满分,,,,
这就比较尴尬了,,
代码语言:javascript
复制
 1 #include<iostream>
 2 using namespace std;
 3 string kong;
 4 string a[1001];//保存每个单词 
 5 int tot=1;//行数 
 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         else
29         {
30             ans=ans+a[i];
31         }
32     }
33     cout<<ans;
34     return 0;
35 }
代码语言:javascript
复制
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-03-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 17:文字排版
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档