博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
17:文字排版
阅读量:6715 次
发布时间:2019-06-25

本文共 1662 字,大约阅读时间需要 5 分钟。

17:文字排版

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

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

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

输入
第一行是一个整数n,表示英文短文中单词的数目. 其后是n个以空格分隔的英文单词(单词包括其前后紧邻的标点符号,且每个单词长度都不大于40个字母)。
输出
排版后的多行文本,每行文本字符数最多80个字符,单词之间以一个空格分隔,每行文本首尾都没有空格。
样例输入
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.
样例输出
One sweltering day, I was scooping ice cream into cones and told my fourchildren they could "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. 表示linux和windows的编译环境不一样, 在dev里格式错误但到了noi里满分,,,, 这就比较尴尬了,,
1 #include
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<
View Code

 

 

转载地址:http://uokmo.baihongyu.com/

你可能感兴趣的文章
Python3 CookBook | 迭代器与生成器
查看>>
深入理解 Android 中的各种 Context
查看>>
Android 6 0 运行时权限处理解析
查看>>
JavaScript引用类型之Array类型API详解
查看>>
数据库事务和MVCC多版本并发控制
查看>>
自定义控件实践-倒计时控件
查看>>
《JavaScript高级程序设计(第三版)》
查看>>
随手记 - Springboot Application Properties 值
查看>>
java B2B2C Springcloud多租户电子商城系统- 分布式事务
查看>>
屏幕方向读取与锁定:Screen Orientation API
查看>>
记:解决angular报错'Missing locale data for the locale "zh-cn"
查看>>
【半月刊 2】前端高频面试题及答案汇总
查看>>
contentSize, contentInset 和 contentOffset的含义
查看>>
vue全家桶
查看>>
springMVC---配置文件解析(web.xml)
查看>>
angular4微信公众号开发遇到的问题
查看>>
React写个GitHub项目管理面板
查看>>
Redis 集群分片&分布式锁的使用
查看>>
String类型
查看>>
一致性 Hash 算法的实际应用
查看>>