解题心得:
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. asp.net5开发中DNX SDK版本的影响

    某次asp.net5开发中遇到了一个很奇怪的问题,引用部分的nuget包没有显示任何错误,如下图: 但是编译时出现了几百个错误: 错误基本都是形如“CS0246 The type or namespa ...

  2. 开始使用JQuery 方法

    使用jQuery需要3个基本步骤: 1. 下载jQuery.js并保存在网页可以存取的位置.下载链接:dowload 2. 在HTML的head里引用jQuery.js 3. 运用jQuery的方法 ...

  3. 使用Pycharm开发python下django框架项目生成的文件解释

    目录MyDjangoProject下表示工程的全局配置,分别为setttings.py.urls.py和wsgi.py,1.其中setttings.py包括了系统的数据库配置.应用配置和其他配置,2. ...

  4. python协程与异步协程

    在前面几个博客中我们一一对应解决了消费者消费的速度跟不上生产者,浪费我们大量的时间去等待的问题,在这里,针对业务逻辑比较耗时间的问题,我们还有除了多进程之外更优的解决方式,那就是协程和异步协程.在引入 ...

  5. bootstrap中使用modal加载kindeditor时弹出层文本框不能输入的问题

    答案来自老外http://stackoverflow.com/questions/14795035/twitter-bootstrap-modal-blocks-text-input-field $( ...

  6. 消除transition闪屏

    消除transition闪屏.css {-webkit-transform-style: preserve-3d;-webkit-backface-visibility: hidden;-webkit ...

  7. java Vamei快速教程17 多线程

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 多线程 多线程(multiple thread)是计算机实现多任务并行处理的一种方 ...

  8. javascript:理解DOM事件

    首先,此文不讨论繁琐细节,但是考虑到读者的心灵感受,本着以积极向上的心态,在此还是会列举示例说明. ​标题为理解DOM事件,那么在此拿一个简单的点击事件为例,希望大家看到这个例子后能触类旁通. DOM ...

  9. 【BZOJ1013】[JSOI2008] 球形空间产生器(高斯消元)

    点此看题面 大致题意: 给定一个\(n\)维球体上的\(n+1\)个点,请你求出这个球体的圆心的位置. 列出方程 这一看就是一道解方程题. 我们可以设这个球体的圆心的位置为\((x_1,x_2,..x ...

  10. 如何从github上拉取项目中的指定目录

    2010开始,对于GitHub上的每一个Git版本库,现在都可以用SVN命令进行操作,而svn命令则是支持部分检出的. 方法如下: 例如我想下载我的nginxinc/kubernetes-ingres ...