/* Name:poj 2271 HTML Author:Unimen Date: 22/04/11 19:30 Description:字符串处理 */ /* 解题报告:字符串处理问题 1、解题时要注意考虑到所有情况 2、输入输出问题,这种题可以用while(scanf("")!=EOF)的形式做 */ #include <iostream> #include <string> using namespace std; int main() { string szWord; int nCount = 0; while(cin>>szWord) { if("<hr>" == szWord) { if(nCount != 0) cout<<endl; int i; for(i=0; i<80; i++) cout<<"-"; cout<<endl; nCount = 0; } else if("<br>" == szWord) { cout<<endl; nCount = 0; } else { if(nCount + szWord.size() + (nCount==0 ? 0 : 1) > 80) { cout<<endl<<szWord; nCount = szWord.size(); } else { if(nCount != 0) cout<<" "; cout<<szWord; nCount += szWord.size() + 1; } } } return 0; }