302. BHTML 1.0

Description



The hypertext markup language BHTML 1.0 has only two paired tags. They are UP /UP and DOWN /DOWN . The UP /UP tag capitalizes all letters inside its body (between an open tag and a close one), and DOWN /DOWN makes all inside the body letters lowercase. You are given the text consisting of latin letters and tags. Your task is to write the text right as it will be shown in the Bernet Explorer browser window. Tags in the text are arranged correctly, i.e. they form correct bracket sequence. If a letter lays inside several tags, its case is defined by the most inner tag.

Input

The input contains the string S with the text. The length of the string is a natural number not exceeding 1000. Tags are always written in uppercase.

Output

Write to the output text after the processing.

Sample Input

sample input
sample output
Thi<UP>sIs<DOWN>EaSY</DOWN>Pr<UP>O</UP>ble</UP>m 
ThiSISeasyPROBLEm 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
using namespace std;
int main()
{
    char s[1010];
    memset(s,0,sizeof(s));
    while(gets(s))
    {
        int len=strlen(s),count(-1);
        int str[500];
        memset(str,0,sizeof(str));
        for(int i=0; i<len; i++)
        {
            if(s[i]=='<')
            {
                if(s[i+1]=='U')
                {
                    str[++count]=1;
                    i+=3;
                }
                else if(s[i+1]=='D')
                {
                    str[++count]=2;
                    i+=5;
                }
                else if(s[i+2]=='U')
                {
                    str[count--]=0;
                    i+=4;
                }
                else if(s[i+2]=='D')
                {
                    str[count--]=0;
                    i+=6;
                }
            }
            else if(str[count]==1) printf("%c",toupper(s[i]));
            else if(str[count]==2) printf("%c",tolower(s[i]));
            else printf("%c",s[i]);
        }
        printf("\n");
        memset(s,0,sizeof(s));
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值