时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Little Hi is writing an algorithm lecture note for Little Ho. To make the note more comprehensible, Little Hi tries to color some of the text. Unfortunately Little Hi is using a plain(black and white) text editor. So he decides to tag the text which should be colored for now and color them later when he has a more powerful software such as Microsoft Word.

There are only lowercase letters and spaces in the lecture text. To mark the color of a piece of text, Little Hi add a pair of tags surrounding the text, <COLOR> at the beginning and </COLOR> at the end where COLOR is one of "red", "yellow" or "blue".

Two tag pairs may be overlapped only if one pair is completely inside the other pair. Text is colored by the nearest surrounding tag. For example, Little Hi would not write something like "<blue>aaa<yellow>bbb</blue>ccc</yellow>". However "<yellow>aaa<blue>bbb</blue>ccc</yellow>" is possible and "bbb" is colored blue.

Given such a text, you need to calculate how many letters(spaces are not counted) are colored red, yellow and blue.

输入

Input contains one line: the text with color tags. The length is no more than 1000 characters.

输出

Output three numbers count_red, count_yellow, count_blue, indicating the numbers of characters colored by red, yellow and blue.

样例输入

<yellow>aaa<blue>bbb</blue>ccc</yellow>dddd<red>abc</red>
样例输出
3 6 3
解题思路:栈的模拟
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;const int maxn = 1000;
char str[maxn];
stack<char> s;
//stack<string> s;int main()
{   bool start;string t;int yellow,red,blue;while(gets(str) != NULL){  if(str[0] == 0) break;while(!s.empty()) s.pop(); //清空栈yellow = red = blue = 0;start = false;int len = strlen(str);for(int i = 0; i < len; i++){if(start == false){if(str[i] == '<')start = true;continue;}if(str[i] == '<' || str[i] == ' ') continue;if(str[i-1] == '<'){if(str[i] == 'y'){s.push('Y');i += 6;}else if(str[i] == 'b'){s.push('B');i += 4;}else if(str[i] == 'r'){s.push('R');i += 3;}else     //出现</color>的情况,要退栈。。{int cnt = 0;  //计算出弹出元素个数while(s.top() >= 'Z'){cnt++, s.pop();}if(s.top() == 'R'){red += cnt;i += 4;}else if(s.top() == 'B'){blue += cnt;i += 5;}else{yellow += cnt;i += 7;}s.pop();}}else if(!s.empty())   //此时栈内非空,说明该元素任属于某一种颜色。。{s.push(str[i]);}}printf("%d %d %d\n",red,yellow,blue);}return 0;
}

Colorful Lecture Note(栈的模拟)相关推荐

  1. hihocoder #1103 : Colorful Lecture Note微软苏州校招笔试 1月10日(字符串处理+栈)

    #1103 : Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorit ...

  2. 【2019牛客暑期多校训练营(第八场)- G】Gemstones(栈,模拟)

    题干: 链接:https://ac.nowcoder.com/acm/contest/888/G 来源:牛客网 Gromah and LZR have entered the seventh leve ...

  3. 【POJ - 1028】 Web Navigation( 栈 or 模拟队列 )

    题干: Standard web browsers contain features to move backward and forward among the pages recently vis ...

  4. 栈(模拟栈,表达式求值)

    模拟栈 #include<iostream>using namespace std;const int N=100010; int stk[N],tt;//向站内插入元素 void pus ...

  5. 模拟栈 java_Java 模拟栈结构

    栈和队列: 通常是作为程序猿的工具,用于辅助构思算法.生命周期较短,执行时才被创建 訪问受限.在特定时刻,仅仅有一个数据可被读取或删除 是一种抽象的结构.内部的实现机制.对用户不可见.比方用数组.链表 ...

  6. 【HDOJ4699】Editor(对顶栈,模拟)

    problem 维护一个整数序列的编辑器,支持5种操作,操作数< 1e6 I x:在光标后插入数x,插入后光标移到x后 D:删除光标前的一个整数 L:光标左移一个位置 R:光标右移一个位置 Q ...

  7. 牛客网 A-吐泡泡 栈的模拟

    链接:https://www.nowcoder.com/acm/contest/74/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  8. **PAT_甲级_1057 Stack (30分) (C++)【字符串处理/栈的模拟/树状数组】

    目录 1,题目描述 题目大意 2,思路 数据结构 函数讲解 1,void update(int x, int v): 2,int getsum(int x): 3,void PeekMedian(): ...

  9. sc169 lecture note

    fn(i)f_n(i)fn​(i) 1,2,3,...N1,2,3,...N1,2,3,...N n,n+1,,...Nn, n+1,, ...Nn,n+1,,...N nnn σ\sigmaσ ∑a ...

最新文章

  1. 0.数据结构学习笔记大纲
  2. Python-EEG工具库MNE中文教程(8)-参考电极简介
  3. asp.net 后台任务作业框架收集
  4. 手机上最小的Linux,Linux没有最小只有更小----361M以下的Linux名单
  5. php怎么关闭oracle连接,PHP 连接 Oracle
  6. 工作失职的处理决定_工作失职的处理决定
  7. 工作307:uni-富文本的实现逻辑跳转
  8. java对比swith和if的不同,浅谈选择结构if语句和switch语句的区别
  9. win7系统的设置在哪里_win10系统改装win7之BIOS设置教程
  10. android 显示多条数据格式,Multipart上传的进度条,包含多个Android文件
  11. java digester_使用digester解析XML配置文件
  12. GameFramework框架——UI底层框架梳理
  13. Segue区别及视图的切换
  14. python为什么会出现无响应怎么办,Python多处理中无响应进程的终止
  15. Codeforces Beta Round #94 (Div. 1 Only)A. Statues
  16. 我要曝光!CDN 省钱大法!
  17. python中print()换行的问题
  18. Mendix Studio Pro/Mendix Studio的离线安装
  19. jav 中 this和super
  20. [ssh]permissions are too open密钥权限过大错误

热门文章

  1. 神策合肥研发中心携手安徽开发者社区,深入交流共促行业发展
  2. 神策数据 2018 校招启程了!
  3. Python3 CookBook | 数字处理
  4. 部署WAR包实时查看Tomcat的状态和日志
  5. openstack 网络简史
  6. Java的日期API真烂
  7. 明晰软件架构与数据结构
  8. “病毒防治”页面中“社区热帖”版块不显示
  9. white board and magnet
  10. 这个学期的总结,下个学期比较坑的事情和要注意的点