水题:HDU-1088-Write a simple HTML Browser(模拟题)
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.
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>.
. 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.
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.
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(模拟题)的更多相关文章
- HDU 1088 Write a simple HTML Browser 有点恶心的字符串题
这题是从某个群里听别人在抱怨这题老是PE,打开status果然满眼的Presentation Error...于是闲着来做了一下. 其实挺水的,不过各种设定多一点,注意一点就行了. 一开始以为词数超过 ...
- 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 ...
- HDU 1088 - Write a simple HTML Browser
直接看sample input = = 又一道模拟. #include <iostream> #include <string> #include <cstdio> ...
- hdu 5641 King's Phone(暴力模拟题)
Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...
- HDU ACM 1088 Write a simple HTML Browser
意甲冠军:出现<br>总结,出现<hr>出口'-',今天的字加上各行的假设是长于80然后包,每个字之前,留下一个空白格,为了输出新行结束. #include<iostre ...
- hdu 2629 Identity Card (字符串解析模拟题)
这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...
- 【HDOJ】1088 Write a simple HTML Browser
题目其实不难,但是要注意题目的要求,当前字数(>0)+当前单词长度+1若超过80则需要回车后,输出当前word,并且重新计数.这道题目的数据感觉比较水,不过测试的时候,最后使用fprintf输出 ...
- hdu 5083 Instruction (稍比较复杂的模拟题)
题意: 二进制指令转汇编指令,汇编指令转二进制指令. 思路: 额,条理分好,想全,思维不能乱. 代码: int findyu(char yu[50],char c){ int l=strlen(yu) ...
- poj1472[模拟题]
Instant Complexity Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2017 Accepted: 698 ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
随机推荐
- collectd 与 logstash配置
节点 node1: 配置logstash node2: 配置collectd, collectd收集本地的信息, 通过配置将信息发送到node1节点 node1安装配置logstash rpm -iv ...
- Elasticsearch支持的字段类型
es支持下列简单的字段类型: String: string Whole number: byte, short, integer, long Floating point: float, double ...
- asp.net 在IIS上配置出现的一些问题
1.可能会遇到一下图的错无.请求的内容似乎是脚本.因而将无法由静态文件处理程序来处理---大概的原因是应用程序池选择错误了.如第二幅图如此解决即可 解决方案如下两个图所示. 我遇到了以上的问题之后能也 ...
- Linux Mint下的conky配置
最近闲来无事,想把自己的Linux Mint弄的再炫酷点,在桌面上显示一些信息,因为我已经装了Cairo-dock,现在就差这个了,下面简单说下整个流程,首先你得安装conky, sudo apt-g ...
- 从零开始的全栈工程师——js篇2.14(表单与计时器)
一.表单 Form input select textarea type=”radio/checkbox/password/button/text/submit/reset/” 表单的事件 oncha ...
- Git 团队常用命令操作指南
命令如下: git clone -b <branch name> [remote repository address] 主要就是在clone的时候,后面添加branch的信息. 报错: ...
- python3基础04(requests常见请求)
#!/usr/bin/env python# -*- coding:utf-8 -*- import requestsimport jsonimport reimport urllib3from ur ...
- Java JDBC链接Oracle数据库
package com.test.test; import java.io.FileInputStream;import java.io.FileNotFoundException;import ja ...
- 传入指定字段名称就可以排序的EF写法
private static IQueryable<T> SetQueryableOrder<T>(this IQueryable<T> query, string ...
- 设置和重置ssh key
查看本地是否有已经生成好的ssh key $ cat ~/.ssh/id_rsa.pub 若有,先删除: $ cd ~ $ rm -rf .ssh 重新生成ssh key ssh-keygen -t ...