poj2271 HTML

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.
本题的题意是html的输出方式,<br>换行,<hr>是输出下划线,但是由于框框只有80列,所以如果接下来的单词的长度使得这行的字符大于80,就要换行输出
本题的主要问题是格式的问题,根据前辈的经验和自己的经验,总结一下几点

1:每行的最后一个单词后没有空格;
  2:如果输出一个单词导致这行长度大于80,那么换行后再输出;
  3:如果<hr>出现在一行的开头,那么在输出“---”前不需要换行;
  4:最后要输出一个换行...
  5.因为你要在每一个单词都加上一个空格的,当然除了最后一个单词之外
  6.输出下划线以后还要输出一个空格(本人在这里PE了很多遍)

附上以下代码:

 #include<stdio.h>
#include<string>
#include<string.h>
#include<iostream>
using namespace std;
char str[];
int main(){
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int out,len;
out=;
while(scanf("%s",str)==){
len=strlen(str);
if(strcmp(str,"<br>")==){
printf("\n");
out=;
}
else if(strcmp(str,"<hr>")==){
if(out!=){
printf("\n");
}
printf("--------------------------------------------------------------------------------\n");
out=;
}
else{
if(out+len>){
out=;
printf("\n");
printf("%s",str);
out=out+len;
}
else{
if(out!=){
out++;
printf(" ");
}
out=out+len;
printf("%s",str);
}
}
}
printf("\n");
}

顺便附上文本显示和调试框的对比图

poj 2271HTML的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

随机推荐

  1. Exclusive-OR(带权并查集)

    Exclusive-OR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 实例理解mapreduce任务的串行运行过程

    一.准备: eclipse,hadoop集群 注意:为了方便测试和修改,我用的是 windows 连接hadoop集群,这样在windows 下直接就能够执行 mapreduce 任务,方便程序调试. ...

  3. AngularJS学习篇(十二)

    AngularJS SQL ASP.NET 中执行 SQL 获取数据 <!DOCTYPE html> <html> <head> <meta charset= ...

  4. ajax参数解析

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  5. Python通过跳板机链接MySQL的一种方法

  6. js 切换全屏

    公司有一个需求就是点击某一个按钮实现全屏切换功能,然后呢我就在网上扒了段代码.封装了一下.使用的小伙伴们可以看看哦! 切换全屏代码 <!DOCTYPE html> <html> ...

  7. 一篇文章让你明白python的装饰器

    在看闭包问题之前先来看看关于python中作用域的问题 变量作用域 对于上述代码中出现错误,肯定没什么疑问了,毕竟b并没有定义和赋值,当我们把代码更改如下后: 再看一个例子: 首先这个错误已经非常明显 ...

  8. concurrent.futures

    concurrent.futures concurrent.futures提供高层次的接口,用来实现异步调用. 这个异步执行可以使用threads(ThreadPoolExecutor)或者proce ...

  9. CentOS 7 yum 安装ownCloud 搭建云盘服务器

    基于CentOS7.0 64位系统+ownCloud 10.0 稳定版本构建 ownCloud 是一个开源免费专业的私有云存储项目,它能帮你快速在个人电脑或服务器上架设一套专属的私有云文件同步网盘,可 ...

  10. iOS上new Date异常解决办法

    最近有一个项目要实现使用Angluar写一个简历模板, 用户输入姓名/生日/简介...等内容, 然后生成一份在线的简历 后来测试时遇到简历模板在Android手机跟Google浏览器上根据生日计算得出 ...