ZOJ 1099 HTML

时间:2023-03-09 02:27:50
ZOJ 1099 HTML

原题链接

题目大意:按照HTML的语法处理一段字符。这道题算是字符串类型的经典,熟练之后可以做一个简单的html解析器了。

解法:没什么好说的,直接代码。

参考代码:

#include<iostream>
#include<string>
using namespace std; void hr(){
cout<<"--------------------------------------------------------------------------------"<<endl;
}
void br(){
cout<<endl;
} int main(){
string html;
int i,j,n,len;
string str; while(cin>>str){
if(str=="<br>"){
br();
len=0;
}
else if(str=="<hr>"){
if(len)cout<<endl;
hr();
len=0;
}
else{
if(len+str.size()<80){
if(len!=0)cout<<' ';
cout<<str;
len+=str.size()+1;
}
else{
cout<<endl;
len=str.size();
cout<<str;
}
}
}
cout<<endl; return 0;
}