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

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

Output

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

Sample Input

<yellow>aaa<blue>bbb</blue>ccc</yellow>dddd<red>abc</red>

Sample Output

3 6 3

题意:统计 yellow、red、blue 标签中字母个数
与括号序列类似,只不过此处的括号为标签
 #include <iostream>
#include <cstdio>
#include <stack>
#include <cctype>
#include <cstring>
using namespace std;
// <yellow>aaa<blue>bbb</blue>ccc</yellow>dddd<red>abc</red> int main(int argc, char const *argv[])
{
char input[];
while(gets(input)){
stack<char> s;
int r_count,y_count,b_count;
r_count = y_count = b_count = ;
for (int i = ; i < strlen(input); ++i)
{
if(input[i] == '<'){
if(input[i+] == 'y'){
s.push('y');
i += ;
continue;
}else if(input[i+] == 'b'){
s.push('b');
i += ;
continue;
}else if(input[i+] == 'r'){
s.push('r');
i += ;
continue;
}else if(input[i+] == '/'){
s.pop();
if(input[i+] == 'y'){
i += ;
continue;
}else if(input[i+] == 'b'){
i += ;
continue;
}else if(input[i+] == 'r'){
i += ;
}
}
}else if(!s.empty()){
if(s.top() == 'r' && isalpha(input[i])){
r_count++;
}else if(s.top() == 'y' && isalpha(input[i])){
y_count++;
}else if(s.top() == 'b' && isalpha(input[i])){
b_count++;
}
}
}
cout << r_count << " " << y_count << " " << b_count << endl;
}
return ;
}

HihoCoder - 1103 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. Colorful Lecture Note(手工栈)

    题目1 : Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorithm ...

  3. Colorful Lecture Note

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

  4. Codeforces Round #287 (Div. 2) D. The Maths Lecture [数位dp]

    传送门 D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input stan ...

  5. Codefores 507D The Maths Lecture( 数位DP )

    D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Leetcode: Number of Islands II && Summary of Union Find

    A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...

  7. awesome-nlp

    awesome-nlp  A curated list of resources dedicated to Natural Language Processing Maintainers - Keon ...

  8. Computer Science Theory for the Information Age-4: 一些机器学习算法的简介

    一些机器学习算法的简介 本节开始,介绍<Computer Science Theory for the Information Age>一书中第六章(这里先暂时跳过第三章),主要涉及学习以 ...

  9. UFLDL实验报告3:Self-taught

    Self-taught 自我学习器实验报告 1.Self-taught 自我学习实验描述 自我学习是无监督特征学习算法,自我学习意味着算法能够从未标注数据中学习,从而使机器学习算法能够获得更大数量的数 ...

随机推荐

  1. Spring Security开发Restful服务

    2-1开发环境安装 1.jdk8安装 2.安装STS    Spring Tool Suite实际上就是一个eclipse,只不过在此基础上又安装了一些插件 3.安装mysql 2-2代码结构介绍 打 ...

  2. 基于wepy和云开发的动漫资讯小程序----233次元

    233次元小程序 # 233次元小程序 项目描述- 基于微信小程序的动漫咨询小程序,采用`wepy`框架开发:- 后台数据采用小程序的云开发存储: 线上体验 部分截图                 ...

  3. [持续交付实践] 研发协作平台:DevOps背景下的组织结构

    前言 今年以来做的事情越来越杂,负责的技术方向越来越广,精力越来越分散(创业公司的典型特点),编码的时间越来越少,有时候也会觉得很疲惫没办法专注一个事情. 除了技术方向上的实践,组织上如何组建一个最优 ...

  4. html 文本解码 xpath 获取html标签

    import htmlimport etree selector = etree.HTML(res) url_h2 = selector.xpath("//a[@_stat='video:p ...

  5. Splunk 丰富数据方法

    方法1: 查找 Step 1.创建CSV文件,首字段为索引字段(关联字段) 2.导入CSV文件,Settings, Lookups, Lookup tables files 3.配置Lookup de ...

  6. hive 学习

    多表查询 SELECT a.user_uid_type, a.user_uid, c.user_id, c.user_type FROM mytable1 a JOIN mytable2 b ON(a ...

  7. 关于c# Debug和Release的区别 (转)

    关于Debug和Release的区别之讨论本文主要包含如下内容: 1. Debug 和 Release 编译方式的本质区别2. 哪些情况下 Release 版会出错2. 怎样“调试” Release ...

  8. Javascript 使用 async 声明符和 await 操作符进行异步操作

    async function 声明用于定义一个返回 AsyncFunction 对象的异步函数 await  操作符用于等待一个Promise 对象.它只能在异步函数 async function 中 ...

  9. linux命令行下xlsx转换成pdf或csv的笔记

    使用libreoffice(可以用yum直接安装,占用了4xxM磁盘空间...) 然后命令行执行: 转换成csv,支持utf-8中文编码: libreoffice  --invisible --con ...

  10. Druid中配置双数据库

    配置如下 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://w ...