This can be solved by combining the sample with the following scenarios.
The code is as follows:
1#include <iostream>2#include <stack>3#include <string>4 using namespacestd;5 6 intMain () {7 intbegin, end;8 while(CIN >> begin >> End, begin! =-1&& End! =-1) {9 stringtext;TenCin.Get(); Getline (cin, text); Onestack<string>prepend, append; A for(intCur =0; Cur < begin; ++cur) { - if(Text[cur] = ='<') { - if(Text[cur +1] =='/') { the Prepend.pop (); Append.pop (); -}Else { - inttail = cur +1; - while(Text[tail]! ='>') ++tail; + stringTag = text.substr (cur, tail-cur +1); - Prepend.push (tag); +Append.push (Tag.insert (1,"/")); A } at } - } - for(intcur = begin; Cur < end; ++cur) { - if(Text[cur] = ='<') { - if(Text[cur +1] =='/') { - Append.pop (); in}Else { - inttail = cur +1; to while(Text[tail]! ='>') ++tail; + stringTag = text.substr (cur, tail-cur +1); -Append.push (Tag.insert (1,"/")); the } * } $ }Panax Notoginseng stringAns = text.substr (begin, End-begin); - while(!Prepend.empty ()) { theans = prepend.top () +ans; Prepend.pop (); + } A while(!Append.empty ()) { theAns + =append.top (); Append.pop (); + } -cout << ans <<Endl; $ } $ return 0; -}
SOJ 1180. Pasting Strings