poj 2271HTML
Description
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
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
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的更多相关文章
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- 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 ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- VS2012 C#生成DLL并调用
1.创建一个C#工程生成DLL 新建->项目->Visual C#->类库->MyMethods 项目建好后,为了理解,将项目中的Class1.cs 文件 重命名为 MySwa ...
- replace to
要注意的是:插入数据的表必须有主键或者是唯一索引!否则的话,replace into 会直接插入数据,这将导致表中出现重复的数据. MySQL replace into 有三种形式: 1. repla ...
- 启动hadoop的命令
start-all.sh 启动所有的Hadoop守护进程.包括NameNode. Secondary NameNode.DataNode.JobTracker. TaskTrack stop-all ...
- AMD与commonJS
CommonJS:它是一个同步的模式.但是这种模式并不适合于浏览器端,如果浏览器同步模式一个一个加载模块,那么打开将会变得非常的慢. AMD:它最大的特点就是可以异步的方式加载模块,具体的不同在于AM ...
- 【APP问题定位(一)】夜神模拟器安装及问题
本文较少下夜神模拟器的使用,包括了夜神安装,APK安装,开发者选项打开. 安装夜神模拟器 到 夜神模拟器 网站自行下载安装文件,双击exe文件安装,选择"自定义安装" ...
- postgis常用操作手册
查询所有函数: SELECT * FROM pg_proc; 更新坐标系st_setsrid,查看坐标系:st_srid 创建空间索引: CREATE INDEX [indexname] ON [ta ...
- [转载] Kafka+Storm+HDFS整合实践
转载自http://www.tuicool.com/articles/NzyqAn 在基于Hadoop平台的很多应用场景中,我们需要对数据进行离线和实时分析,离线分析可以很容易地借助于Hive来实现统 ...
- SDN/NFV趋势思考点滴
一.为什么控制器.网管OSS融合? 1.云化是趋势:传统网络架构管理规模达到瓶颈:微服务架构通过扩充多实例解决管理规模问题.2.NFV是趋势:设备运营商传统网元在云化,以软件形式提供VNF:3.运维体 ...
- python 实用案例 supervisord管理进程详解
Supervisor是由python语言编写,基于linux操作系统的一款服务器管理工具,用以监控服务器的运行,发现问题能立即自动预警及自动重启等功能.Supervisor类似于monit,monit ...
- 【Java入门提高篇】Day3 抽象类与接口的比较
抽象类跟接口都讲完了,现在来做一个比较. 其实说实话,没有多大的可比较性,它们是完全不同的两个东西,它们的抽象不在同一个层级上.但是为了让大家更好的理解,还是做一个比较吧,毕竟它们都很抽象(233). ...