HihoCoder - 1103 Colorful Lecture Note

时间:2022-09-28 13:37:11

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 &num;1103 &colon; Colorful Lecture Note微软苏州校招笔试 1月10日&lpar;字符串处理&plus;栈&rpar;

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

  2. Colorful Lecture Note&lpar;手工栈)

    题目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 &num;287 &lpar;Div&period; 2&rpar; D&period; The Maths Lecture &lbrack;数位dp&rsqb;

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

  5. Codefores 507D The Maths Lecture&lpar; 数位DP &rpar;

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

  6. Leetcode&colon; Number of Islands II &amp&semi;&amp&semi; 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&colon; 一些机器学习算法的简介

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

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

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

随机推荐

  1. android RelativeLayout 动态设置高度

    定义: private RelativeLayout mrlay; 调高度: mrlay = (RelativeLayout) findViewById(R.id.rlay_1); android.v ...

  2. Unity3D中C&num;和js方法相互调用

    通过查找资料,Unity3D中C#和js要相互调用彼此的方法,js文件必须放在"Standard Assets". "Pro Standard Assets" ...

  3. 014--VS2013 C&plus;&plus; c&plus;&plus;定时动画

    资源图片 //全局变量HBITMAP girl[7];HDC mdc, hdc;int num; //--------------------------------------------InitI ...

  4. 批处理命令 - if

    0.功能 Performs conditional processing in batch programs. 执行批处理程序中的条件处理. 1.简介 IF [NOT] ERRORLEVEL numb ...

  5. NGUI类之间的关系和架构

    NGUI Drawcall 1.使用同一个altals的元素尽量放在同一个UIPanel下面,在NGUI中,它消耗的drawcall是以每个Panel为独立计算单位进行计算的. 2.如果一个UIPan ...

  6. Redis分区

    数据是怎样分布在多个Redis实例上的 分区是将你的数据分布在多个Redis实例上,以至于每个实例只包含一部分数据. 为什么分区是有用的呢 Redis分区有两个主要目标: 它允许更大的数据库,用许多计 ...

  7. k8s调度器、预选策略及调度方式

    一.k8s调度流程 1.(预选)先排除完全不符合pod运行要求的节点2.(优先)根据一系列算法,算出node的得分,最高没有相同的,就直接选择3.上一步有相同的话,就随机选一个 二.调度方式 1.no ...

  8. redis&colon;order set有序集合类型的操作(有序集合)

    1. order set有序集合类型的操作(有序集合) 有序集合是在无序集合的基础上加了一个排序的依据,这个排序依据叫score,因此声明一个集合为有序集合的时候要加上score(作为排序的依据) 1 ...

  9. VHDL 乐曲演奏电路设计

    前言 无源蜂鸣器在直流信号下不会响,需要方波驱动.输入不同频率的方波会发出不同音调的声音,方波的幅值决定了声音的响度. 目标 乐曲发生电路在节拍(4Hz)的控制下根据乐谱产生合适的分频系数.分频器根据 ...

  10. 洛谷P2016战略游戏

    传送门啦 战略游戏这个题和保安站岗很像,这个题更简单,这个题求的是士兵人数,而保安站岗需要求最优价值. 定义状态$ f[u][0/1] $ 表示 $ u $ 这个节点不放/放士兵 根据题意,如果当前节 ...