码迷,mamicode.com
首页 > 其他好文 > 详细

文字排版

时间:2018-11-24 19:51:25      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:sum   luci   rda   没有   smi   内存   aced   换行   sid   

文字排版

发布时间: 2017年10月27日 10:15   最后更新: 2017年10月29日 20:40   时间限制: 1000ms   内存限制: 128M

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

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

第一行是一个整数n,表示英文短文中单词的数目. 其后是n个以空格分隔的英文单词(单词包括其前后紧邻的标点符号,且每个单词长度都不大于40个字母)。

排版后的多行文本,每行文本字符数最多80个字符,单词之间以一个空格分隔,每行文本首尾都没有空格。

复制
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.
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.

输入样例以空格分割,未换行
一定注意换行要写在前面
要不就空格了
还有一定是else if 不是 if
if会导致每行开头多出来个空格


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n;
scanf("%d",&n);
char a[41]={0};
int sum=0,i;
for(i=0;i<n;i++)
{
scanf("%s",&a);
if(sum+1+strlen(a)>80)
{
printf("\n");
sum=0;
}
if(i>0)
{
printf(" ");
sum++;
}
printf("%s",a);
sum=sum+strlen(a);
}
return 0;
}

文字排版

标签:sum   luci   rda   没有   smi   内存   aced   换行   sid   

原文地址:https://www.cnblogs.com/huaa/p/10013077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!