Colorful Lecture Note(手工栈)
题目1 : 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 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
注意:需要用gets来读空格。#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
#define maxn 1100
struct Sta
{
char word[maxn];
int cnt = ;
};
Sta sta[];
char a[];
int main()
{
gets(a);
{
int k = ;
int cnt1 = ;
int cnt2 = ;
int cnt3 = ;
int j;
for(int i = ; a[i] != '\0'; i++)
{
if(a[i] == ' ')
continue;
int k1 = ;
int flag = ;
if(a[i]=='<')
{
k++;
for(j = i+; a[j] != '>'; j++)
{
if(a[j]=='/')
flag = ;
sta[k].word[k1++] = a[j];
} sta[k].word[k1] = '\0';
i=j; if(flag)
{
if(strcmp(sta[k-].word,"yellow")== )
cnt1 += sta[k-].cnt;
if(strcmp(sta[k-].word,"blue")== )
cnt2 += sta[k-].cnt;
if(strcmp(sta[k-].word,"red")== )
cnt3 += sta[k-].cnt;
sta[k-].cnt = sta[k].cnt = ;
k=k-;
}
continue;
}
sta[k].cnt++;
}
printf("%d %d %d\n", cnt3,cnt1,cnt2);
}
return ;
}
/*<yellow>aaa<blue>bbb </blue>ccc</yellow>dddd<red>abc</red>*/
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
Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorithm lectu ...
- HihoCoder - 1103 Colorful Lecture Note
Little Hi is writing an algorithm lecture note for Little Ho. To make the note more comprehensible, ...
- 递归转手工栈处理的一般式[C语言]
是任意形式的递归,是化解的一般式. 主题所谓的“递归调用化解为栈处理”,意思是,将递归函数调用化解为“一个由stack_push stack_pop stack_top等函数调用组成的循环式子”.这里 ...
- dfs手写栈模板
在竞赛中如果系统栈很小的话,过深的递归会让栈溢出,这个时候我们就要自己手写栈,将递归转化成手工栈. 方法其实也很简单. 基本思路上,我们就是用栈不断的pop,push.但是何时push,何时pop呢? ...
- 树的dfs序 && 系统栈 && c++ rope
利用树的dfs序解决问题: 就是dfs的时候记录每个节点的进入时间和离开时间,这样一个完整的区间就是一颗完整的树,就转化成了区间维护的问题. 比如hdu3887 本质上是一个求子树和的问题 #incl ...
- HDU 3887 Counting Offspring (树状数组+人工模拟栈)
对这棵树DFS遍历一遍,同一节点入栈和出栈之间访问的节点就是这个节点的子树. 因此节点入栈时求一次 小于 i 的节点个数 和,出栈时求一次 小于 i 的节点个数 和,两次之差就是答案. PS.这题直接 ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- ISPA
来自CSDN的Rachel Zhang 4. Improved SAP 算法 本次介绍的重头戏.通常的 SAP 类算法在寻找增广路时总要先进行 BFS,BFS 的最坏情况下复杂度为 O(E),这样使得 ...
随机推荐
- CodeForces 19D Points
Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coo ...
- 负重前行的婚纱线上路 - i天下网商-最具深度的电商知识媒体
负重前行的婚纱线上路 - i天下网商-最具深度的电商知识媒体 负重前行的婚纱线上路
- ASP.NET 实现PDF文件下载
本文介绍了一种在ASP.NET中下载文件的方法. 方法一:可能是最简单的.最短的方式: Response.ContentType = "application/pdf"; Resp ...
- 生命周期-初识IOS
经常因为生命周期的事情,而视图顺序加载错误,或者出现一系列的小错误并且修改不出来,程序员不知道生命周期确实挺可悲的. IOS生命周期: 自上而下的执行,并且viewDidLoad只会执行一次,所以我们 ...
- java基础之代理
代理的定义,代理的应用,代理的特性
- oracle(天猫处方药留言sql)
" ?> .dtd" > <sqlMap namespace="TmallTcMessage"> <typeAlias alias ...
- 除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。
在 SELECT 后加 TOP 100 PERCENT .
- AngularJs练习Demo4
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...
- 数据库分库分表(sharding)系列(一)拆分实施策略和示例演示
本文原文连接: http://blog.csdn.net/bluishglc/article/details/7696085 ,转载请注明出处!本文着重介绍sharding切分策略,如果你对数据库sh ...
- 数据泵导出/导入Expdp/impdp
一下转自 http://blog.csdn.net/jionjionyoushen/article/details/6789686 数据泵导出/导入Expdp/impdp Oracle 10g引入了D ...