302. BHTML 1.0
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
Memory limit: 65536 kilobytes
input: standard
output: standard
output: standard
The hypertext markup language BHTML 1.0 has only two paired tags. They are
![](http://acm.sgu.ru/cache/8a3003255478a8b4b4e52f2f212fd348.png)
![](http://acm.sgu.ru/cache/50a9ef76c8bf8eb91244ed909528dac5.png)
![](http://acm.sgu.ru/cache/8a3003255478a8b4b4e52f2f212fd348.png)
![](http://acm.sgu.ru/cache/50a9ef76c8bf8eb91244ed909528dac5.png)
![](http://acm.sgu.ru/cache/8a3003255478a8b4b4e52f2f212fd348.png)
![](http://acm.sgu.ru/cache/50a9ef76c8bf8eb91244ed909528dac5.png)
![](http://acm.sgu.ru/cache/8a3003255478a8b4b4e52f2f212fd348.png)
![](http://acm.sgu.ru/cache/50a9ef76c8bf8eb91244ed909528dac5.png)
![](http://acm.sgu.ru/cache/8a3003255478a8b4b4e52f2f212fd348.png)
![](http://acm.sgu.ru/cache/50a9ef76c8bf8eb91244ed909528dac5.png)
![](http://acm.sgu.ru/cache/8a3003255478a8b4b4e52f2f212fd348.png)
![](http://acm.sgu.ru/cache/50a9ef76c8bf8eb91244ed909528dac5.png)
![](http://acm.sgu.ru/cache/8a3003255478a8b4b4e52f2f212fd348.png)
![](http://acm.sgu.ru/cache/50a9ef76c8bf8eb91244ed909528dac5.png)
![](http://acm.sgu.ru/cache/8a3003255478a8b4b4e52f2f212fd348.png)
![](http://acm.sgu.ru/cache/50a9ef76c8bf8eb91244ed909528dac5.png)
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.
Example(s)
sample input | sample output |
Thi<UP>sIs<DOWN>EaSY</DOWN>Pr<UP>O</UP>ble</UP>m | ThiSISeasyPROBLEm |
Online Contester Team © 2002 - 2010. All rights reserved. |
思路:栈的应用,具体看代码;
AC代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
using namespace std;
char str[1005];
int main() {
while(gets(str) != NULL) {
stack<int> s;
int len = strlen(str);
for(int i = 0; i < len; i++) {
if(str[i] == '<') {
if(str[i+1] == 'U') { s.push(1); i += 3; }
else if(str[i+1] == 'D') { s.push(2); i += 5; }
else if(str[i+1] == '/') {
s.pop();
if(str[i+2] == 'U') i += 4;
else if(str[i+2] == 'D') i += 6;
}
}
else if(s.empty()) {
printf("%c", str[i]);
}
else if(s.top() == 1) {
if(str[i] >= 'a' && str[i] <= 'z') printf("%c", str[i]-32);
else printf("%c", str[i]);
}
else if(s.top() == 2) {
if(str[i] >= 'A' && str[i] <= 'Z') printf("%c", str[i]+32);
else printf("%c", str[i]);
}
}
printf("\n");
}
return 0;
}