文字排版
来源:互联网 发布:linux dd命令 编辑:程序博客网 时间:2024/05/16 05:33
【描述】
给一段英文短文,单词之间以空格分隔(每个单词应包括其前后紧邻的标点符号)。请将短文重新排版,要求如下:
每行不超过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 upto make their purchases. The three youngest each gave me a quick hug, grabbedtheir cones and raced back outside. But when my teenage son at the end of theline finally got his turn to "buy" his ice cream, he gave me twohugs. "Keep the changes," he said with a smile.
【输出示例】
Onesweltering 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 maketheir purchases. The three youngest each gave me a quick hug,
grabbed their conesand raced back outside. But when my teenage son at the end
of the line finallygot his turn to "buy" his ice cream, he gave me two hugs.
"Keep thechanges," he said with a smile.
【C代码】
---------------
#include<stdio.h>
#include<string.h>
#defineWORD_SIZE 40
#defineLINE_SIZE 80
intmain(void) {
char word[WORD_SIZE + 1];
int length = 0;
int n, t;
scanf("%d", &n);
t = n;
while(n > 0) {
scanf("%s", word);
if(length + strlen(word) + 1 <= LINE_SIZE && n != t) {
printf(" ");
++length;
}
else if(length + strlen(word) + 1 > LINE_SIZE) {
printf("\n");
length = 0;
}
length += strlen(word);
printf("%s",word);
--n;
}
return 0;
}
- 文字排版
- 文字排版
- 文字排版字体怎么排版
- 平面设计文字排版
- PHOTOSHOP段落文字排版
- 关于文字排版方法
- lettering个性化文字排版
- 图片和文字排版
- iOS文字排版(CoreText)
- ios文字排版
- css基础-文字排版
- coretext IOS文字排版
- CSS 文字、段落排版
- 7.27文字排版
- iOS文字排版(CoreText)
- CoreText文字排版
- CSS格式化文字排版
- CoreText-文字排版
- Junit测试相关
- 详述DRAM、SDRAM及DDR SDRAM的概念
- Xposed源码分析
- iOS工程如何支持64-bit
- 盘点8种CSS实现垂直居中水平居中的绝对定位居中技术
- 文字排版
- mysql_config_editor
- .net连接MySql ,获取中文字段乱码
- JS获取验证码,并验证
- calloc
- cisco6509switch防火墙模块
- Android本地通讯录
- MapReduce高级编程——自定义InputFormat
- 唯有爱与引力不可辜负