// 1. 类似英语文章,当该行放不下此单词时,将该单词放到下一行,不会分成两部分
// 2. 通过stringstream获取每个单词,不用考虑中间空格,当加上该单词以及一个空格未满80,则输出单词并在其后加上空格;否则换行,输出单词,重新计数行内字母数
#include <iostream>
#include <sstream>
#include <cstring>
using namespace std;
char out[90];
int main(){
string str, s;
int len = 0;
bool first = true;
while(getline(cin, str)){
stringstream ss(str);
while(ss >> s){
if(s == "<br>"){
cout << endl;
len = 0;
first = true;
continue;
}
if(s == "<hr>"){
if(len != 0)
cout << endl;
cout << "--------------------------------------------------------------------------------" << endl;
len = 0;
first = true;
continue;
}
if(len + s.length() + 1 > 80){
cout << endl;
cout << s;
len = s.length();
first = false;
}else{
if(first == false){
cout << ' ';
len++;
}
cout << s;
first = false;
len += s.length();
}
}
}
cout << endl;
return 0;
}
HDU 1088 Write a simple HTML Browser
最新推荐文章于 2024-05-23 18:18:28 发布