解题心得:
1、仔细读题,细心细心。。。。。。
2、题的几个要求:超过八十个字符换一行,<br>换行,<hr>打印一个分割线,最后打印一个新的空行。主要是输出要求比较多。
3、检验的时候可以使用文件读入和文件输出,这样方便判别。


题目:

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<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
bool first = false;
//FILE *f;//注意使用文件指针
char a[90];
int leng = 0;
//f = fopen("new.txt","w");//文件指针会自动向下转移不用手动
while(~scanf("%s",a))
{
if(strcmp(a,"<br>") == 0)//c语言中可这样判别两个字符串是否一样,如果一样会返回0;
{
first = true;
printf("\n");
//fprintf(f,"%c",10);
leng = 0;
continue;
} if(strcmp(a,"<hr>") == 0)
{
if(leng != 0)//连续两个<br>要注意有没有多余的空行。
{
printf("\n");
//fprintf(f,"%c",10);
first = true;
}
printf("--------------------------------------------------------------------------------\n");
//fprintf(f,"%s","--------------------------------------------------------------------------------");
//fprintf(f,"%c",10);
leng = 0;
first = true;
continue;
}
else
{
if(leng == 0)
{
first = false;
printf("%s",a);
leng += strlen(a);
//for(int i=0;i<strlen(a);i++)
//fprintf(f,"%c",a[i]);
}
else if((leng+strlen(a)+1)<=80)
{
printf(" %s",a);
//fprintf(f,"%c",32);
//for(int i=0;i<strlen(a);i++)
//fprintf(f,"%c",a[i]);
leng = strlen(a) + 1 + leng;//这里+1是因为有空格;
}
else
{
printf("\n%s",a);
//fprintf(f,"%c",10);
//for(int i=0;i<strlen(a);i++)
//fprintf(f,"%c",a[i]);
leng = strlen(a);
first = false;
}
}
}
if(!first)//要有一个新的空行,不然PE;
printf("\n");
//fclose(f);//文件指针最后要关闭
return 0;
}

水题:HDU-1088-Write a simple HTML Browser(模拟题)的更多相关文章

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

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

  2. 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 i ...

  3. HDU 1088 - Write a simple HTML Browser

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

  4. hdu 5641 King's Phone(暴力模拟题)

    Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...

  5. HDU ACM 1088 Write a simple HTML Browser

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

  6. hdu 2629 Identity Card (字符串解析模拟题)

    这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...

  7. 【HDOJ】1088 Write a simple HTML Browser

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

  8. hdu 5083 Instruction (稍比较复杂的模拟题)

    题意: 二进制指令转汇编指令,汇编指令转二进制指令. 思路: 额,条理分好,想全,思维不能乱. 代码: int findyu(char yu[50],char c){ int l=strlen(yu) ...

  9. poj1472[模拟题]

    Instant Complexity Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2017   Accepted: 698 ...

  10. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

随机推荐

  1. spring MVC之注解开发控制器(二)

    开发表单控制器 在传统的Spring MVC开发方法中,是通过扩展SimpleFormController类来创建简单的表单控制器.这样就定义了基本的表单处理流程,并允许通过覆盖几个生命周期方法来定制 ...

  2. mybatis + log4j2 问题 java.lang.NoClassDefFoundError: org/apache/logging/log4j/spi/AbstractLoggerWrapper

    root cause java.lang.NoClassDefFoundError: org/apache/logging/log4j/spi/AbstractLoggerWrapper 网上资料比较 ...

  3. table-列组

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. bootstrapValidator 如何重新启用提交按钮

    bootstrapValidator 使用中,由于字段检查等原因,致使提交按钮失效.如何重新启用提交按钮呢? 下面一句代码可以实现启用提交按钮: $('#loginForm').bootstrapVa ...

  5. iOS - 协议实现的例子

    在实际开发中,协议的应用非常广泛,以下是实际应用的例子. 1.协议的定义: myProtocolDelegate.h // // myProtocolDelegate.h // zlwPlayerAp ...

  6. java 创建一个新的http 请求的一种实现方式

    项目中遇到要在后台向集群中的其他一台服务器发送一个请求,参考了网上一些材料,最终完成了需求.代码如下 /** * @Title requestURLWithPost * @Description:发送 ...

  7. 虚拟机中Ubuntu安装vmtools

    1.解压vmtools文件为VMWARETO.TGZ VMtools文件一般在系统桌面,如果没有可以点击左上方的"虚拟机-安装VMware Tools"即可出现在桌面,也可以通过U ...

  8. hihoCoder hiho一下 第一周 #1032 : 最长回文子串 (Manacher)

    题意:给一个字符串,求最长回文子串的长度. 思路: (1)暴力穷举.O(n^3) -----绝对不行. 穷举所有可能的出现子串O(n^2),再判断是否回文O(n).就是O(n*n*n)了. (2)记录 ...

  9. Ruby 学习笔记(一)

    环境搭建 本文基于Mac OS,windowns坑较多,建议使用Mac. xcode-select -p 检查是否安装xcode-select, 如果没有,通过xcode-select --insta ...

  10. noip模拟赛#23

    T1:n个元素的集合.要求取出k个子集,使得k个子集交集为空集.问有多少中取法. =>推了很久...想的是从k等于2的情况推到k等于3的情况....然后k=2推出来了k=3也推出来了...推了挺 ...