hdu 1088 Write a simple HTML Browser

qq172108805發表於2012-03-22
#include<iostream>
#include<string>
using namespace std;
string hr = "--------------------------------------------------------------------------------";
int main()
{
    string s;
    int tag=0,len;
    while(cin>>s)
    {
        len=s.size();
        if(s=="<br>")
        {
            cout<<endl;
            tag=0;
        }else if(s=="<hr>")
        {
            if(tag!=0)
            {
                cout<<endl;
            }
            cout<<hr<<endl;
            tag=0;
        }else
        {
            if((tag+1+len)<=80)
            {
                if(tag)
                {
                    cout<<" ";
                    tag++;
                }
                cout<<s;
                tag+=len;
            }else
            {
                cout<<endl;
                cout<<s;
                tag=len;
            }
        }
    }
    cout<<endl;
    return 0;
}

相關文章