POJ 2271 HTML

[url]http://poj.org/problem?id=2271[/url]

[size=medium]题意:给你HTML代码,翻译出来
要点:
①每行长度不得超过80
②HTML标签只有2个
<br>:换行
<hr>:换行【若本来就在开头不用先换行】再输出80个'-',接着换行
③最后要换行

[color=red]Sample Input[/color]
[color=blue]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.
[/color]
[color=red]Sample Output[/color]
[color=blue]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.[/color][/size]

[size=medium]题目飞一般的水,只要你细心,会用打表调试,并且测试极端情况的正确性
如输入:[/size]
[color=blue][size=x-small]11111111112222222222333333333344444444445555555555666666666677777777778888888888
11111111112222222222333333333344444444445555555555666666666677777777778888888888
11111111112222222222333333333344444444445555555555666666666677777777778888888888[/size][/color]


#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h>
using namespace std;

int main()
{
//fstream out ("d:\\ans.txt", ios::out);
int num = 0;
char word[85];
while (scanf ("%s", word) != EOF)
{
if (!strcmp (word, "<br>"))
{
printf ("\n")/*, out << endl*/;
num = 0;
continue;
}
if (!strcmp (word, "<hr>"))
{
if (num > 0)
printf ("\n")/*, out << endl*/;
num = 0;
printf ("--------------------------------------------------------------------------------\n");
//out << "--------------------------------------------------------------------------------\n";
continue;
}
int len = strlen(word);
if (num == 0)
num = len;
else
{
if (num + 1 + len > 80) //+1是因为空格
printf ("\n"), num = len/*, out << endl*/;
else printf (" "), num += 1 + len/*, out << ' '*/;
}
printf ("%s", word)/*, out << word*/;
}
printf ("\n");
//out << endl;
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值