http://poj.org/problem?id=2271
题意:给你HTML代码,翻译出来
要点:
①每行长度不得超过80
②HTML标签只有2个
<br>:换行
<hr>:换行【若本来就在开头不用先换行】再输出80个'-',接着换行
③最后要换行
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.
题目飞一般的水,只要你细心,会用打表调试,并且测试极端情况的正确性
如输入:
11111111112222222222333333333344444444445555555555666666666677777777778888888888
11111111112222222222333333333344444444445555555555666666666677777777778888888888
11111111112222222222333333333344444444445555555555666666666677777777778888888888
#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;
}
分享到:
相关推荐
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
poj分类poj分类poj分类poj分类
* 较为复杂的动态规划:例如 poj1191、poj1054、poj3280、poj2029、poj2948、poj1925、poj3034。 数学 1. 组合数学: * 加法原理和乘法原理。 * 排列组合。 * 递推关系:例如 poj3252、poj1850、poj1019、poj...
北大POJ1159-Palindrome 解题报告+AC代码
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
POJ1083的代码,POJ1083的代码,POJ1083的代码
poj 百练 题目分类 poj 百练 题目分类
POJ1048,加强版的约瑟夫问题 难度中等
北大POJ2002-Squares 解题报告+AC代码
poj 1001答案
POJ2968代码有用,欢迎下载,POJ代码
poj 1440解题报告 poj 1440解题报告 poj 1440解题报告 poj 1440解题报告
poj 3083解题报告poj 3083解题报告poj 3083解题报告poj 3083解题报告