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. GitCam一款Gif动画制作软件

    本篇文章由:http://www.sollyu.com/gitcam-a-gif-animation-software/ 说明 GifCam是一款小巧.免费的录制电脑屏幕并制作成GIF动画的软件,具有 ...

  2. ubuntu下virtualenv的复制

    将一个用户下的virtualenv复制到另一个用户下.直接复制无法使用,source后的python依旧是系统自带的python. 原始env名:/home/llx/work/nn/nnenv.bak ...

  3. html定义对象

    <object>定义一个对象<param>为对象定义一个参数 参数的名称:name = "" 参数的值:value=""classid: ...

  4. IE11的CSS兼容性问题

    最近测试给了我一大堆BUG,一瞅发现全是IE11的.吐槽一下这个浏览器真的比较特立独行.很多默认的样式跟别的浏览器不同,而且最明显的一点应该是padding左右内边距往往比别的浏览器大了一倍.但是当需 ...

  5. textarea出现多余的空格

    今天使用textarea标签,调用数据的时候,出现一些多余的空格,如何改变属性都不能够经过某属性将空格去掉,经过查询,看了zuyi532的专栏(http://blog.csdn.net/zuyi532 ...

  6. 2016年1月编程语言排行榜:Java荣获2015年度冠军

    Java因于2015年人气增幅最大(+ 5.94%),故获得2015年的TIOBE指数的编程语言奖,同时成为15年年度冠军, Visual Basic.NET(+ 1.51%)和Python(+ 1. ...

  7. 【python】【转】if else 和 elif

    else和elif语句也可以叫做子句,因为它们不能独立使用,两者都是出现在if.for.while语句内部的.else子句可以增加一种选择:而elif子句则是需要检查更多条件时会被使用,与if和els ...

  8. 版本控制工具git入门

    版本控制工具的历史 不说了,放张图 两者的区别:集中式需要一个中心服务器放置最新的文件,需要联网操作.分布式可以再不联网的情况下操作,前提要拥有版本库 git安装  略 github注册 略 如何在g ...

  9. Html DOM 常用属性和方法

    Node对象的节点类型***************************************************接口 nodeType常量 nodeType值 备注Element Node ...

  10. 这是从word发的第一篇博客。

    喜欢做的事,怎么样都不会厌倦. 以前只知道office功能强大,但不太清楚到底还能干些啥,印象最深的是outlook了,自己也在用,挺好 今天偶然发现,word还能发布博客,真是太惊喜了 这算是一篇实 ...