SGU - 302 - BHTML 1.0 (栈的应用)
来源:互联网 发布:2015中国汽车出口数据 编辑:程序博客网 时间:2024/06/14 06:42
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 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.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;}
1 0
- SGU - 302 - BHTML 1.0 (栈的应用)
- SGU-302. BHTML 1.0
- 302. BHTML 1.0
- CF-51B - bHTML Tables Analisys(easy+栈)
- sgu 508 Black-white balls(贝叶斯公式的应用)
- sgu 302
- SGU 134 Centroid(树的重心)
- SGU 134. Centroid(树的重心)
- SGU 102 Coprimes ---- 欧拉函数、素数的应用&&GCD水题
- SGU 242(MaxFlow)
- SGU 102(Coprimes)
- (sgu-344)Weed
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- Python中怎样使用shape计算矩阵的行和列
- 李红霞p-27-6题
- 常见OJ评判结果对照表,作为ACMer你懂得!
- JVMTI 中的JNI系列函数,线程安全及调试技巧
- HDU 1166 敌兵布阵(单点更新)
- SGU - 302 - BHTML 1.0 (栈的应用)
- WdatePicker日历控件使用方法
- eclipse如何重命名包名
- linux 下的svn 安装
- zoj 2107 最近点对
- html5学习渐阶笔记---介绍html5
- HDU 1698 Just a Hook(区间更新)
- android乱码问题解决
- 面向对象编程其实与亚里士多德的“实体论”很相似