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 自我学习实验描述 自我学习是无监督特征学习算法,自我学习意味着算法能够从未标注数据中学习,从而使机器学习算法能够获得更大数量的数 ...
随机推荐
- 小程序navigateBack,子页面传值给父页面
子页面 let page = getCurrentPages(); let prevPage = page[page.length - 2]; prevPage.setData({ lxr :item ...
- ubuntu下多版本OpenCV的共存与使用
首先,OpenCV历史版本下载:https://www.opencv.org/releases.html 一.把不同版本的OpenCV安装在不同位置 下载好OpenCV源码,在安装之前打开CMakeL ...
- 2018-2019-2 20165205《网络对抗技术》Exp4 恶意代码分析
2018-2019-2 20165205<网络对抗技术>Exp4 恶意代码分析 实验要求 监控你自己系统的运行状态,看有没有可疑的程序在运行. 分析一个恶意软件,就分析Exp2或Exp3中 ...
- spring boot 请求地址带有.json 兼容处理
项目以前时spring mvc的,现在升级为spring boot ,有些请求地址带有.json后缀,在请求spring boot项目时,无法匹配控制器,spring boot默认选择禁用后缀模式匹配 ...
- SSM的搭建
1.首先是工具的准备. eclipse jdk1.7 maven 3.5.4 tomcat 8.5 2.工具环境的搭建 首先,new建立选择maven project工程,勾选simple proje ...
- leetcode top 100 题目汇总
首先表达我对leetcode网站的感谢,与高校的OJ系统相比,leetcode上面的题目更贴近工作的需要,而且支持的语言广泛.对于一些比较困难的题目,可以从讨论区中学习别人的思路,这一点很方便. 经过 ...
- Vue note 2
1.异步加载组件 一般单页面的缺点是首屏加载比较慢,因为首屏会把所有所需静态资源全部加载,对于中大型项目来说这样可能不是很合理.初步采用异步组件的方式,配合webpack,组件内部可以采用: comp ...
- fiddler抓https包
若手机端安装证书后还是无法抓取到https请求,请注意手机端证书开关是否开启: eg:ios 设置---通用---关于本机---证书信任设置:开启证书信任 若还是无法抓包,则可以进行一下操作: 给fi ...
- python学习Day7 数据类型的转换,字符编码演变历程
一.数据类型的转换 1.1.1.字符转列表:lst1 = str.split(默认空格,也可依据指定字符分界),若无分界字符,就没法拆分,这时可以直接放进list转成列表 ----> s1 = ...
- Java Script 简介
Java Script 简介 JavaScript 是世界上最流行的编程语言. 这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记本电脑.平板电脑和智能手机等设备.JavaScrip ...