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.
注意点:
(1) 每行最多80个字符,如果加上最后一个单词大于80,则最后一个单词移到下一行。
(2) <hr>如果处于当前行字符数等于0的情况,则直接输出,否则先输出回车,在输出<hr>,只含有<br>和<hr>标签
(3) 文章最后要有一个回车

equals表示的相等,是指向对象的相等;而compareTo的相等,是内容的相等。

不过其中有一个问题,很奇怪~我用equals老是PE,用compareTo就没问题了~~~弄不懂~

代码注释标识了!

有知道原因的大牛,请在评论区指点下,谢啦~

(哈哈~解决啦~其实这2个都可以的~)

之前的PE应该不是这个原因~

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
Scanner sc = new Scanner(System.in); String result = new String("");
String str;
while (sc.hasNext()) {
str = sc.next();
if ("".equals(str)) {
continue;
}
if ("<br>".equals(str)) {
System.out.println(result);
result = "";
} else if ("<hr>".equals(str)) {
if (result.compareTo("")!=0) {
// if (!"".equals(result)) {//这个是一样的!
System.out.println(result);
}
gong.print();
result = "";
} else { String temp = result;
if ((temp + " " + str).length() < 80) {
if (!"".equals(result)) {
result += " " + str;
} else {
result = str;// 每一行的第一个输入
}
} else {
System.out.println(result);
result = str;
}
}
}
if (!("".equals(result))) {
System.out.println(result);
}
}
} class gong {
static void print() {
for (int i = 0; i < 80; i++)
System.out.print("-");
System.out.println();
}
}

HDOJ/HDU 1088 Write a simple HTML Browser(HTML字符串)的更多相关文章

  1. HDU 1088 Write a simple HTML Browser 有点恶心的字符串题

    这题是从某个群里听别人在抱怨这题老是PE,打开status果然满眼的Presentation Error...于是闲着来做了一下. 其实挺水的,不过各种设定多一点,注意一点就行了. 一开始以为词数超过 ...

  2. 【HDOJ】1088 Write a simple HTML Browser

    题目其实不难,但是要注意题目的要求,当前字数(>0)+当前单词长度+1若超过80则需要回车后,输出当前word,并且重新计数.这道题目的数据感觉比较水,不过测试的时候,最后使用fprintf输出 ...

  3. HDU 1088 - Write a simple HTML Browser

    直接看sample input = = 又一道模拟. #include <iostream> #include <string> #include <cstdio> ...

  4. HDU ACM 1088 Write a simple HTML Browser

    意甲冠军:出现<br>总结,出现<hr>出口'-',今天的字加上各行的假设是长于80然后包,每个字之前,留下一个空白格,为了输出新行结束. #include<iostre ...

  5. HDOJ/HDU 1982 Kaitou Kid - The Phantom Thief (1)(字符串处理)

    Problem Description Do you know Kaitou Kid? In the legend, Kaitou Kid is a master of disguise, and c ...

  6. HDOJ(HDU).1412 {A} + {B} (STL SET)

    HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...

  7. HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...

  8. HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)

    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...

  9. HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)

    HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...

随机推荐

  1. scrapy, 自带命令行调用工具.

    #-*- coding:utf-8 -*- from scrapy import cmdline cmdline.execute("scrapy crawl dmoz".split ...

  2. 00_ForTest

    -----该页是爬虫的测试页请忽略------- 1234545@qq.comadasdsdasdsad阿打算多少其热情为 asdasdasdasd4w5wsdvv啊实打实大 啊实打实大asdasda ...

  3. ubuntu netbeans compile ygopro client with google protobuf lib

    environment: ubuntu 16.04 netbeans 8.2 ygopro Fluorohydride with Irrlicht Game Engine 问题1: google pr ...

  4. 读书笔记之 - javascript 设计模式 - 工厂模式

    一个类或者对象中,往往会包含别的对象.在创建这种对象的时候,你可能习惯于使用常规方式,即用 new 关键字和类构造函数. 这会导致相关的俩个类之间产生依赖. 工厂模式,就是消除这俩个类之间的依赖性的一 ...

  5. Plugin 'FEDERATED' is disabled 或 1067错误 启动错误与“服务 mysql 意外停止”解决方法

    MYSQL启动报1067错误,系统日志中是“服务 mysql 意外停止” Mysql日志中则是:“Plugin 'FEDERATED' is disabled” 网我在网上找到解决方案:1.在MY.I ...

  6. C#面向对象的学习笔记

    1.面向对象的3要素: 封装:将不需要显示的代码封装到一个方法中,只对外提供方法名,用户不需关心内部实现. 继承:子类继承父类,公用父类的代码,大大提高了代码的重用,贴近生活也符合人类的编程思想. 多 ...

  7. 对BFC的理解

    转载http://www.cnblogs.com/lhb25/p/inside-block-formatting-ontext.html 在解释 BFC 是什么之前,需要先介绍 Box.Formatt ...

  8. View和ViewGroup的区别 -- Touch事件处理

    View.java源码: /frameworks/base/core/java/android/view/View.java View.java的 dispatchTouchEvent 方法: 经过一 ...

  9. 关于优化C#程序的五十种方法

    一.用属性代替可访问的字段 1..NET数据绑定只支持数据绑定,使用属性可以获得数据绑定的好处: 2.在属性的get和set访问器重可使用lock添加多线程的支持. 二.readonly(运行时常量) ...

  10. Javascript 备忘

    1遍历所有属性 var person={fname:"John",lname:"Doe",age:25}; for (x in person) { txt=tx ...