fmt
来源:互联网 发布:免费程序化交易软件 编辑:程序博客网 时间:2024/04/30 23:40
Unix 的 fmt 程序可以对文本中的段落进行重排,保证每一行不超过 72 个字符。重排时它会遵守以下规则:
- 新的一行可以从任何一个有空格的地方开始。如果开始一个新行,则在上一行的末尾和新行的开始都不应该有任何空格。
- 在输出时,可以删除段落中的换行。文章的段落是通过一个空白行来划分的。
- 在行尾不应该有任何空格。
- 如果在一长串的字符间没有空格,且其长度超过了 72 个字符,则应该把它们放在一个单独的行上。
Sample Imput
Unix fmt
The unix fmt program reads lines of text, combining
and breaking lines so as to create an
output file with lines as close to without exceeding
72 characters long as possible. The rules for combining and breaking
lines are as follows.
1. A new line may be started anywhere there is a space in the input.
If a new line is started, there will be no trailing blanks at the
end of the previous line or at the beginning of the new line.
2. A line break in the input may be eliminated in the output, provided
it is not followed by a space or another line break. If a line
break is eliminated, it is replaced by a space.
Sample Output
Unix fmtThe unix fmt program reads lines of text, combining and breaking linesso as to create an output file with lines as close to without exceeding72 characters long as possible. The rules for combining and breakinglines are as follows. 1. A new line may be started anywhere there is a space in the input.If a new line is started, there will be no trailing blanks at the end ofthe previous line or at the beginning of the new line. 2. A line break in the input may be eliminated in the output,provided it is not followed by a space or another line break. If a linebreak is eliminated, it is replaced by a space.
Source
Miguel Revilla 2002-06-15 测试输入 期待的输出 时间限制 内存限制 额外进程 测试用例 1以文本方式显示- Unix fmt↵
- ↵
- The unix fmt program reads lines of text, combining↵
- and breaking lines so as to create an↵
- output file with lines as close to without exceeding↵
- 72 characters long as possible. The rules for combining and breaking↵
- lines are as follows.↵
- ↵
- 1. A new line may be started anywhere there is a space in the input.↵
- If a new line is started, there will be no trailing blanks at the↵
- end of the previous line or at the beginning of the new line.↵
- ↵
- 2. A line break in the input may be eliminated in the output, provided↵
- it is not followed by a space or another line break. If a line↵
- break is eliminated, it is replaced by a space.↵
以文本方式显示- Unix fmt↵
- ↵
- The unix fmt program reads lines of text, combining and breaking lines↵
- so as to create an output file with lines as close to without exceeding↵
- 72 characters long as possible. The rules for combining and breaking↵
- lines are as follows.↵
- ↵
- 1. A new line may be started anywhere there is a space in the input.↵
- If a new line is started, there will be no trailing blanks at the end of↵
- the previous line or at the beginning of the new line.↵
- ↵
- 2. A line break in the input may be eliminated in the output,↵
- provided it is not followed by a space or another line break. If a line↵
- break is eliminated, it is replaced by a space.↵
1秒64M0ple Input
- Unix fmt↵
- ↵
- The unix fmt program reads lines of text, combining↵
- and breaking lines so as to create an↵
- output file with lines as close to without exceeding↵
- 72 characters long as possible. The rules for combining and breaking↵
- lines are as follows.↵
- ↵
- 1. A new line may be started anywhere there is a space in the input.↵
- If a new line is started, there will be no trailing blanks at the↵
- end of the previous line or at the beginning of the new line.↵
- ↵
- 2. A line break in the input may be eliminated in the output, provided↵
- it is not followed by a space or another line break. If a line↵
- break is eliminated, it is replaced by a space.↵
- Unix fmt↵
- ↵
- The unix fmt program reads lines of text, combining and breaking lines↵
- so as to create an output file with lines as close to without exceeding↵
- 72 characters long as possible. The rules for combining and breaking↵
- lines are as follows.↵
- ↵
- 1. A new line may be started anywhere there is a space in the input.↵
- If a new line is started, there will be no trailing blanks at the end of↵
- the previous line or at the beginning of the new line.↵
- ↵
- 2. A line break in the input may be eliminated in the output,↵
- provided it is not followed by a space or another line break. If a line↵
- break is eliminated, it is replaced by a space.↵
#include <stdio.h>
#include <string.h>
main()
{
char a[100000];
int i=0,j,n=0,m,s[20000],x=0,y=0,d=0,c;
while((a[i++]=getchar())!=EOF)
{
}
for(j=0;j<i;j++)
{
if((a[j]=='\n')&&(a[j+1]!='\n')&&(a[j-1]!='\n'))
{
a[j]=' ';
}
}
for(m=0;m<i-2;m++)
{
if(m!=0&&a[m-1]!='\n')
{
if(a[m]==' ')
{
for(d=m;d<=m+71;d++)
{if(a[d]!=' ') {m=d;break;}}
}
}
x=m+71;
if(x>=i-2) {x=i-3;}
for(d=m;d<=x;d++)
{
if(a[d]=='\n')
{
for(c=m;c<d;c++)
{printf("%c",a[c]);}
printf("\n");printf("\n");
m=d+1;goto k;
}
}
if(a[x]==' '&&a[x-1]!=' ')
{
for(y=m;y<x;y++)
{
putchar(a[y]);
}
m=x;
printf("\n");
}
else if(a[x-1]==' '&&a[x]==' ')
{
for(y=x-1;1;y--)
{
if(a[y]!=' ') break;
}
for(d=m;d<=y;d++)
{
printf("%c",a[d]);
}
m=x;printf("\n");
}
else
{
if(a[x+1]==' ')
{
for(c=m;c<=x;c++)
{printf("%c",a[c]);}
}
else
{
for(d=x;d>=m;d--)
{
if(a[d]==' ')break;
}
if(d==m-1)
{
for(y=m;;y++){if (a[y]==' ') break;}
for(c=m;c<y;c++) printf("%c",a[c]);
printf("\n");m=y;goto k;
}
for(y=d;y>=m;y--)
{
if(a[y]!=' ') break;
}
for(c=m;c<=y;c++)
{printf("%c",a[c]);}
}
printf("\n");
m=d;
}
k:;
}
}
- fmt
- fmt
- fmt
- <fmt
- fmt标签
- jstl fmt
- fmt jstl
- fmt标签
- jstl fmt
- jstl fmt
- fmt标签
- 110308 Fmt
- jstl fmt
- jstl fmt
- jstl fmt
- fmt:date
- jstl fmt
- fmt:formatDate
- 模拟退火算法的个人理解
- Sort using
- struts2的一些笔记
- 编写简单java程序
- 网站导航思考
- fmt
- rmq 算法学习
- 常用控件的使用方法--(TextView/EditText/Button/Menu) -计算器代码
- 改变D3D中的渲染状态---SetRenderState
- 请不要做浮躁的嵌入式系统工程师
- 实现 Java 多线程并发控制框架
- 2012-10-23
- JSON解析
- libgdx中的测试代码