您的位置:首页 > Web前端 > HTML

HDU 1088 — Write a simple HTML Browser

2015-07-12 10:29 736 查看
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1088

题意:

1、遇到<br>换行;

2、遇到<hr>输出

“--------------------------------------------------------------------------------”

3、每行长度不得超过80,单词间有空格;

#include<stdio.h>
#include<string.h>
char str[1500];
int lon = 0;
int main()
{
	while(scanf("%s", str)!=EOF)
	{
		if(strcmp(str, "<br>") == 0)
		{
			lon = 0;
			printf("\n");
		}
		else if(strcmp(str, "<hr>") == 0)
		{
			if(!lon)
			printf("--------------------------------------------------------------------------------\n");
			else
			printf("\n--------------------------------------------------------------------------------\n");
			lon = 0;
		}
		else
		{
			int len = strlen(str);
			if(!lon)
			{
				printf("%s", str);
				lon = len;
			}
			else if(lon+len+1>80)
			{
				printf("\n%s", str);
				lon = len;
			}
			else
			{
				printf(" %s", str);
				lon+=len+1;
			}
		}
	}
	printf("\n");		//结束换行 
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: