HDOJ/HDU 1088 Write a simple HTML Browser(HTML字符串)

时间:2021-11-19 04:21:19

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&sol;HDU 1982 Kaitou Kid - The Phantom Thief &lpar;1&rpar;&lpar;字符串处理&rpar;

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

  6. HDOJ&lpar;HDU&rpar;&period;1412 &lbrace;A&rcub; &plus; &lbrace;B&rcub; &lpar;STL SET&rpar;

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

  7. HDOJ&lpar;HDU&rpar;&period;1754 I Hate It &lpar;ST 单点替换 区间最大值&rpar;

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

  8. HDOJ&lpar;HDU&rpar;&period;1166 敌兵布阵 &lpar;ST 单点更新 区间求和&rpar;

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

  9. HDOJ&lpar;HDU&rpar;&period;2844 Coins &lpar;DP 多重背包&plus;二进制优化&rpar;

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

随机推荐

  1. HTML5上传图片到ASP&period;NET&period;MVC

    @{ ViewBag.Title = "Home Page";} <!DOCTYPE HTML PUBLIC><html><head> < ...

  2. sql语句 当前时间查找重复 时间戳转换

    查找重复数据 select id, name, memo from A ) >= ) mysql 当前时间 SELECT NOW(); //2015-10-27 16:43:45 UNIX时间戳 ...

  3. March of the Penguins

    poj3498:http://poj.org/problem?id=3498 题意:某个冰块上有a只企鹅,总共可以跳出去b只,问是否可能所有的企鹅都跳到某一块冰块上,输出所有的可能的冰块的编号. 由于 ...

  4. PowerShell 中使用json对象的性能比较

    PowerShell v3 – Creating Objects With [pscustomobject] – it’s fast! September 19, 2011powershell, v3 ...

  5. 《第一行代码》学习笔记12-UI(1)

    1.程序需要注销或者退出,用一个专门的集合类对所有的活动进行管理即可. 2.可视化编辑工具不利于真正了解界面背后的实现原理,通常这种方式制作的界面都不具有很好的屏幕适配性, 而且当需要编写较为复杂的界 ...

  6. Node&period;JS &plus; MongoDB技术浅谈

    看到一个Node.JS + MongoDB的小样例,分享给大家.魔乐科技软件学院(www.mldnjava.cn)的讲座 Node.JS + MongoDB技术讲座          云计算 +大数据 ...

  7. &lbrack;Swust OJ 465&rsqb;--吴奶奶买鱼&lpar;0-1背包&plus;dfs&rpar;

    题目链接:http://acm.swust.edu.cn/problem/465/ 还有一道题只是描述不一样,方法一模一样(http://acm.swust.edu.cn/problem/644/) ...

  8. elasticsearch data importing

    ElasticSearch stores each piece of data in a document. That's what I need. Using the bulk API. Trans ...

  9. vue-schart : vue&period;js 的图表组件

    介绍 vue-schart 是使用vue.js封装了sChart.js图表库的一个小组件.支持vue.js 1.x & 2.x 仓库地址:https://github.com/lin-xin/ ...

  10. IoC和DI的基本概念的思维导图

    最近在学习Spring开发,IoC这个概念让我有点儿迷糊,控制反转这四个字是在是无法做到望文生义,于是乎就找了一些材料来学习,研究了半天,绘制了下面这幅思维导图.仅供参考!