#include <stdio.h>
#define MAXCOL 10
#define TABIN 8
char line[MAXCOL];
int exptab(int pos);
int findblnk(int pos);
void printl(int pos);
int newpos(int pos);
main()
{
int c, pos = 0;
int temp = 1;
while ((c = getchar())!=EOF)
{
line[pos] = c;
if(c == '/t')
pos = exptab(pos);//若为制表符,把它转换成空格,并且该行结束。直接输出
else if(c == '/n'){
printl(pos);
pos = 0;
}
else if(++pos >= MAXCOL){ //这里的空格不管的
pos = findblnk(pos);//整理,去掉最后的空格
printl(pos);
pos = newpos(pos); //找到新的最早的位置。重置过后。
}
}
}
/*printl:print line until pos column*/
void printl(int pos)
{
int i;
for (i = 0; i<pos; ++i)
putchar(line[i]);
if(pos > 0)
putchar('/n');
}
/*exptab: expand tab into blanks*/
int exptab(int pos)
{
line[pos] = ' ';
for(++pos; pos<MAXCOL && pos %TABIN != 0; ++pos)
line[pos] = ' ';//ÔÚ¸ÃÐÐÓöµ½ÖƱí·û£¬ÔòÔÚÓöµ½ÏÂÒ»¸öÖƱí·û֮ǰʣϵÄÓÿոñÌîÂú¡£
if(pos<MAXCOL)
return pos;
else{
printl(pos);
return 0;
}
}
/*findblnk: find blank's position*///去掉末尾的空格
int findblnk(int pos)
{
while(pos >0 && line[pos] != ' ')
--pos;
if(pos == 0)
return MAXCOL; // no blanks
else
return pos+1;
}
int newpos(int pos)
{
int i, j;
if(pos <= 0 || pos >= MAXCOL)
return 0;
else{
i = 0;
for(j = pos; j<MAXCOL; ++j)
{
line[i] = line[j];
++i;
}
return i;
}
}