http://acm.sgu.ru/problem.php?contest=0&problem=302

标签匹配的问题很多时候都用到栈。

#include <cstdio>
#include 
<cctype>
#include 
<stack>

using namespace std;

int main(void) {
    
char s[1001];
    scanf (
"%s", s);
    stack
<bool> sta;
    
char* t = s;
    
while (*t) {
        
if (*== '<' && *(t+1!= '/') {
            
if (*(t+1== 'U') {
                sta.push(
0);
                t 
+= 4;
            } 
else {
                sta.push(
1);
                t 
+= 6;
            }
        } 
else if (*== '<') {
            
if (*(t+2== 'U') {
                t 
+= 5;
            } 
else {
                t 
+= 7;
            }
            sta.pop();
        } 
else {
            
if (sta.empty()) {
                putchar(
*t++);
            } 
else if (sta.top()) {
                putchar(tolower(
*t++));
            } 
else {
                putchar(toupper(
*t++));
            }
        }
    }
    putchar(
'\n');
    
return 0;
}


posted on 2010-05-11 14:07 Willing 阅读(421) 评论(0)  编辑 收藏 引用 所属分类: ACM

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理