HihoCoder - 1103 Colorful Lecture Note
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的更多相关文章
- hihocoder #1103 : Colorful Lecture Note微软苏州校招笔试 1月10日(字符串处理+栈)
#1103 : Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorit ...
- Colorful Lecture Note(手工栈)
题目1 : Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorithm ...
- Colorful Lecture Note
Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorithm lectu ...
- 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 ...
- Codefores 507D The Maths Lecture( 数位DP )
D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 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 ...
- awesome-nlp
awesome-nlp A curated list of resources dedicated to Natural Language Processing Maintainers - Keon ...
- Computer Science Theory for the Information Age-4: 一些机器学习算法的简介
一些机器学习算法的简介 本节开始,介绍<Computer Science Theory for the Information Age>一书中第六章(这里先暂时跳过第三章),主要涉及学习以 ...
- UFLDL实验报告3:Self-taught
Self-taught 自我学习器实验报告 1.Self-taught 自我学习实验描述 自我学习是无监督特征学习算法,自我学习意味着算法能够从未标注数据中学习,从而使机器学习算法能够获得更大数量的数 ...
随机推荐
- Docker笔记——Docker安装及制作镜像
1 Docker安装本文中Docker运行环境为Ubuntu 14.04.1 LTS 3.13.0-32-generic x64参考:https://docs.docker.com/v1.11/eng ...
- Powerdesigner16 逆向 postgresql9.2
参考配置连接:https://www.cnblogs.com/simpleZone/p/5489781.html 过程中遇到的问题: 1.Powerdesigner需要用32位的jdk进行逆向,所以需 ...
- MSMQ—确认队列和响应队列
一.MSMQ——消息的响应(响应队列) 如果需要从接收程序中获得比确认消息更多的信息(消息确认参考二),就可以使用响应队列.响应队列类似于一般队列,但原始发生程序吧该队列用作接收程序,原始接收 程序把 ...
- python3下获取主流浏览器和python的安装路径
#coding=utf-8#python3下获取主流浏览器和python的安装路径#by dengpeiyou date:2018-07-09import winreg,os #取得浏览器的安装路径d ...
- 《2018面向对象程序设计(Java)课程学习进度条》
周次 (阅读/编写)代码行数 发布博客量/博客评论数量 课堂/课余学习时间(小时) 最满意的编程任务 第一周 50/40 1/0 6/4 九九乘法表 第二周 100/80 1/0 6/8 实验5,6, ...
- PHP:自己写的mysql操作类
a{ font-weight: bold; display: block; text-align: center; color: #5887bf; font-size: 22px; } .conten ...
- Python 中文数字转阿拉伯数字
#只能转数字,传参中包含非数字会错. def t(str): zhong={'零':0,'一':1,'二':2,'三':3,'四':4,'五':5,'六':6,'七':7,'八':8,'九':9}; ...
- CentOS编译安装软件过程中遇到zlib.h: No such file or directory
使用命令:yum install zlib-devel 解决问题.
- Multiple dex files define Lcom/google/gson/internal/Streams$AppendableWriter$CurrentWrite;
开发中引入第三方 aar 时编译同过,运行时出现问题: Multiple dex files define Lcom/google/gson/internal/Streams$AppendableWr ...
- python 图片识别灰度
# -*- coding: cp936 -*- from skimage import io,transform,color import numpy as np def convert_gray(f ...