HDOJ/HDU 1088 Write a simple HTML Browser(HTML字符串)
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字符串)的更多相关文章
- HDU 1088 Write a simple HTML Browser 有点恶心的字符串题
这题是从某个群里听别人在抱怨这题老是PE,打开status果然满眼的Presentation Error...于是闲着来做了一下. 其实挺水的,不过各种设定多一点,注意一点就行了. 一开始以为词数超过 ...
- 【HDOJ】1088 Write a simple HTML Browser
题目其实不难,但是要注意题目的要求,当前字数(>0)+当前单词长度+1若超过80则需要回车后,输出当前word,并且重新计数.这道题目的数据感觉比较水,不过测试的时候,最后使用fprintf输出 ...
- HDU 1088 - Write a simple HTML Browser
直接看sample input = = 又一道模拟. #include <iostream> #include <string> #include <cstdio> ...
- HDU ACM 1088 Write a simple HTML Browser
意甲冠军:出现<br>总结,出现<hr>出口'-',今天的字加上各行的假设是长于80然后包,每个字之前,留下一个空白格,为了输出新行结束. #include<iostre ...
- 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 ...
- HDOJ(HDU).1412 {A} + {B} (STL SET)
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
随机推荐
- HDU 4627 The Unsolvable Problem(简单题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 题目大意:给定一个整数n(2 <= n <= 109),满足a+b=n并且[a,b] ...
- bc
调试脚本报错bc: command not found 原因是因为这个linux环境里没有安装计算器工具bc 用 apt-get install bc 或者 yum -y install bc 安装后 ...
- 【制作镜像】virsh
首先进入到图形界面 常用virsh指令: 1)virsh list 列出当前虚拟机列表,不包括未启动的 2)virsh list --all 列出所有虚拟机,包括所有已经定义的虚拟机 3)virsh ...
- IOS 学习笔记 2015-03-24 OC-API-不可变字符串
大部分是模仿// // main.m // OC-API-不可变字符串 // // Created by wangtouwang on 15/3/25. // Copyright (c) 2015年 ...
- SQL Join(连接查询)
1.连接查询分为: inner join(自然连接,自连接) Left join(左连接)/Left outer join(左外连接):效果一样 Right join(右连接)/Right outer ...
- webapp中的日期选择
你是否在开发webapp时,选择用哪种第三方日期选择控件绞尽脑汁? 其实不用那么麻烦,现在移动端都是WebKit内核,支持HTML5,其实只要弱弱的将input中将type="date&qu ...
- mac 生成支付宝的rsa公钥和私钥 php版本
openssl genrsa -out rsa_private_key.pem 1024 公钥 openssl rsa -in rsa_private_key.pem -pubout -out rsa ...
- 针对IE的CSS hack 全面 实用
.all IE{property:value\9;} .gte IE 8{property:value\0;} .lte IE 7{*property:value;} .IE 8/9{property ...
- shell编程的一些例子2
控制语句: 1.if语句 demo_if #!/bin/bash if [ $# -ne 1 ] then echo "参数多于一个" exit 1 fi if [ -f &quo ...
- bss段为什么需要初始化?
我们都知道bss段需要初始化,但是这是为什么呢? 通过浏览资料,我们都会发现,bss段是不会出现在程序下载文件(*.bin *.hex)中的,因为全都是0.如果把它们出现在程序下载文件中,会增加程序下 ...