SGU-302. BHTML 1.0

来源:互联网 发布:js根据class删除tr 编辑:程序博客网 时间:2024/06/14 00:48
#include <iostream>#include <stack>#include <string>using namespace std;stack<int> zhan;int main (){    string s1, s2;    while(cin>>s1)    {        s2.clear();        for(int i = 0; i < (int)s1.length(); i++)        {            if(s1[i] == '<'&&s1[i+1] == 'U'){zhan.push(1); i+=3;}            else if(s1[i] == '<'&&s1[i+1] == 'D'){zhan.push(-1); i+=5;}            else if(s1[i] == '<'&&s1[i+1] == '/'){zhan.pop(); i+=(s1[i+2] == 'U'?4:6);}            else            {                if(zhan.empty())s2+=s1[i];                else if(zhan.top() == 1)                s2+=(s1[i]-=((s1[i]>='A'&&s1[i]<='Z')?0:32));                else if(zhan.top() == -1)                s2+=(s1[i]+=((s1[i]>='a'&&s1[i]<='z')?0:32));            }        }        cout<<s2<<endl;    }    return 0;}
思路较简单,不做多余解释》
原创粉丝点击