HDOJ1088 Write a simple HTML Browser 【simulation】

Write a simple HTML Browser

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 6917    Accepted Submission(s): 1853

Problem Description

If you ever tried to read a html document on a Macintosh, you know how hard it is if no Netscape is installed.

Now, who can forget to install a HTML browser? This is very easy because most of the times you don‘t need one on a MAC because there is a Acrobate Reader which is native to MAC. But if you ever need one, what do you do?

Your task is to write a small html-browser. It should only display the content of the input-file and knows only the html commands (tags) <br> which is a linebreak and <hr> which is a horizontal ruler. Then you should treat all tabulators, spaces and newlines
as one space and display the resulting text with no more than 80 characters on a line.

Input

The input consists of a text you should display. This text consists of words and HTML tags separated by one or more spaces, tabulators or newlines.

A word is a sequence of letters, numbers and punctuation. For example, "abc,123" is one word, but "abc, 123" are two words, namely "abc," and "123". A word is always shorter than 81 characters and does not contain any ‘<‘ or ‘>‘. All HTML tags are either <br>
or <hr>.

Output

You should display the the resulting text using this rules:

. If you read a word in the input and the resulting line does not get longer than 80 chars, print it, else print it on a new line.

. If you read a <br> in the input, start a new line.

. If you read a <hr> in the input, start a new line unless you already are at the beginning of a line, display 80 characters of ‘-‘ and start a new line (again).

The last line is ended by a newline character.

Sample Input

Hallo, dies ist eine
ziemlich lange Zeile, die in Html
aber nicht umgebrochen wird.
<br>
Zwei <br> <br> produzieren zwei Newlines.
Es gibt auch noch das tag <hr> was einen Trenner darstellt.
Zwei <hr> <hr> produzieren zwei Horizontal Rulers.
Achtung       mehrere Leerzeichen irritieren

Html genauso wenig wie

mehrere Leerzeilen.

Sample Output

Hallo, dies ist eine ziemlich lange Zeile, die in Html aber nicht umgebrochen
wird.
Zwei

produzieren zwei Newlines. Es gibt auch noch das tag
--------------------------------------------------------------------------------
was einen Trenner darstellt. Zwei
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
produzieren zwei Horizontal Rulers. Achtung mehrere Leerzeichen irritieren Html
genauso wenig wie mehrere Leerzeilen.

注意输出结尾要添加回车。

#include <stdio.h>
#include <string.h>
char buf[82], str[82], hr[81];
int id, len;

int main(){
	//freopen("data.out", "w", stdout);
	memset(hr, ‘-‘, 80);
	while(scanf("%s", str) == 1){
		if(str[0] == ‘<‘){
			buf[id] = ‘\0‘;
			if(str[1] == ‘b‘){ puts(buf); }
			else{
				if(id){ puts(buf); }
				puts(hr);
			}
			id = 0;
			continue;
		}
		len = strlen(str);
		if(id == 0){
			memcpy(buf, str, len);
			id += len;
		}else{
			if(id + len >= 80){
				buf[id] = ‘\0‘; puts(buf);
				memcpy(buf, str, len); id = len;
			}else{
				buf[id++] = ‘ ‘; memcpy(buf + id, str, len);
				id += len;
			}
		}
	}
	if(id){ buf[id] = ‘\0‘; printf(buf); }
	printf("\n");
	return 0;
}

HDOJ1088 Write a simple HTML Browser 【simulation】

时间: 2024-11-05 14:53:58

HDOJ1088 Write a simple HTML Browser 【simulation】的相关文章

HDU1088 Write a simple HTML Browser【字符串处理】【水题】

Write a simple HTML Browser Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8533    Accepted Submission(s): 2402 Problem Description If you ever tried to read a html document on a Macintosh, yo

HDU 4978 A simple probability problem 【凸包】【几何】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4978 题目大意:给你在平面上一些平行的线,线之间的距离是D,然后在给你一些不共线的点,每两点之间都有线相连,现在问这些点连成的线与平面上平行的线相交的概率. 这里要先介绍一个模型:蒲丰投针问题 知道了这个模型之后我们就能解决只有两个点的问题了,P=2L/πD (L为针长,D为平行线间距) 但是给出的是有很多个点,所以我们还要知道蒲丰投针问题扩展,将给出的点构造成一个凸包,若是凸包内部的线可以和平面上

【multiset】hdu 5349 MZL&#39;s simple problem

[multiset]hdu 5349 MZL's simple problem 题目链接:hdu 5349 MZL's simple problem 题目大意 n次操作,插入元素.删除最小元素.查询最大元素并输出. C++STL的multiset的使用 set--多元集合(元素不可重复),multiset--可重复元素的多元集合 多元集合(MultiSets)和集合(Sets)相像,只不过支持重复对象.(具体用法请参照set容器) set和multiset内部是以平衡二叉树实现的: 从内部数据结

【DataStructure】One of queue usage: Simulation System

Statements: This blog was written by me, but most of content  is quoted from book[Data Structure with Java Hubbard] [Description] This simulationillustrates objectoriented programming(OOP). Java objects are instantiated to represent all the interacti

FluentData -Micro ORM with a fluent API that makes it simple to query a database 【MYSQL】

官方地址:http://fluentdata.codeplex.com/documentation MYSQL: MySQL through the MySQL Connector .NET driver. 连接字符串:Server=127.0.0.1;Database=testDB;Uid=root;Pwd=jnex;<system.data> <DbProviderFactories> <add name="MySQL Data Provider" i

【BZOJ3489】A simple rmq problem kd-tree

[BZOJ3489]A simple rmq problem Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一次的数,并且要求找的这个数尽可能大.如果找不到这样的数,则直接输出0.我会采取一些措施强制在线. Input 第一行为两个整数N,M.M是询问数,N是序列的长度(N<=100000,M<=200000) 第二行为N个整数,描述这个序列{ai},其中所有1<=ai<=N 再下面M行,每

【BZOJ4999】This Problem Is Too Simple! 离线+树状数组+LCA

[BZOJ4999]This Problem Is Too Simple! Description 给您一颗树,每个节点有个初始值. 现在支持以下两种操作: 1. C i x(0<=x<2^31) 表示将i节点的值改为x. 2. Q i j x(0<=x<2^31) 表示询问i节点到j节点的路径上有多少个值为x的节点. Input 第一行有两个整数N,Q(1 ≤N≤ 100,000:1 ≤Q≤ 200,000),分别表示节点个数和操作个数. 下面一行N个整数,表示初始时每个节点的初

【HDOJ】2451 Simple Addition Expression

递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41-1000: 3*4*41-10000: 3*4*4*41-10^n: 3*4^(n-1).并且需要注意,一旦发现某一位大于3,则应立即跳出累加的循环.比如,f(133) = 24,f(143) = 24.同时,单独讨论个位的情况.28行的break处理该种情况. 1 #include <cstdio&g

【POJ】3468 A Simple Problem with Integers ——线段树 成段更新 懒惰标记

A Simple Problem with Integers Time Limit:5000MS   Memory Limit:131072K Case Time Limit:2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each