简单模拟:
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
char s[81];
int main()
{
int first = 1; //判断是否是在行首
int cnt = 0;
while(~scanf("%s", s))
{
int i, j;
if(!strcmp(s, "<br>"))
{
printf("\n");
cnt = 0;
first = 1; //每次换行后下一行必定在行首,所以first = 1;
continue;
}
if(!strcmp(s, "<hr>"))
{
if(!first)
{
printf("\n");
first = 1; //同上
}
for(i = 0 ; i < 80 ; i++)
{
printf("-");
}
printf("\n");
cnt = 0; //清零
first = 1; //同上
continue;
}
if(first)
{
printf("%s", s);
cnt += strlen(s);
first = 0; //清零
continue;
}
cnt += (strlen(s)+1); //有空格,所以长度为strlen(s)+1
first = 0;
if(cnt >= 80)
{
printf("\n");
printf("%s", s);
cnt = strlen(s); //重新赋值
first = 0;
}
else
{
printf(" %s", s);
}
}
if(!first) printf("\n"); //最后以新行结束
return 0;
#include <stdlib.h>
#include <string.h>
using namespace std;
char s[81];
int main()
{
int first = 1; //判断是否是在行首
int cnt = 0;
while(~scanf("%s", s))
{
int i, j;
if(!strcmp(s, "<br>"))
{
printf("\n");
cnt = 0;
first = 1; //每次换行后下一行必定在行首,所以first = 1;
continue;
}
if(!strcmp(s, "<hr>"))
{
if(!first)
{
printf("\n");
first = 1; //同上
}
for(i = 0 ; i < 80 ; i++)
{
printf("-");
}
printf("\n");
cnt = 0; //清零
first = 1; //同上
continue;
}
if(first)
{
printf("%s", s);
cnt += strlen(s);
first = 0; //清零
continue;
}
cnt += (strlen(s)+1); //有空格,所以长度为strlen(s)+1
first = 0;
if(cnt >= 80)
{
printf("\n");
printf("%s", s);
cnt = strlen(s); //重新赋值
first = 0;
}
else
{
printf(" %s", s);
}
}
if(!first) printf("\n"); //最后以新行结束
return 0;
}