题目1 : Colorful Lecture Note

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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(手工栈)的更多相关文章

  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

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

  3. HihoCoder - 1103 Colorful Lecture Note

    Little Hi is writing an algorithm lecture note for Little Ho. To make the note more comprehensible, ...

  4. 递归转手工栈处理的一般式[C语言]

    是任意形式的递归,是化解的一般式. 主题所谓的“递归调用化解为栈处理”,意思是,将递归函数调用化解为“一个由stack_push stack_pop stack_top等函数调用组成的循环式子”.这里 ...

  5. dfs手写栈模板

    在竞赛中如果系统栈很小的话,过深的递归会让栈溢出,这个时候我们就要自己手写栈,将递归转化成手工栈. 方法其实也很简单. 基本思路上,我们就是用栈不断的pop,push.但是何时push,何时pop呢? ...

  6. 树的dfs序 && 系统栈 && c++ rope

    利用树的dfs序解决问题: 就是dfs的时候记录每个节点的进入时间和离开时间,这样一个完整的区间就是一颗完整的树,就转化成了区间维护的问题. 比如hdu3887 本质上是一个求子树和的问题 #incl ...

  7. HDU 3887 Counting Offspring (树状数组+人工模拟栈)

    对这棵树DFS遍历一遍,同一节点入栈和出栈之间访问的节点就是这个节点的子树. 因此节点入栈时求一次 小于 i 的节点个数 和,出栈时求一次 小于 i 的节点个数 和,两次之差就是答案. PS.这题直接 ...

  8. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  9. ISPA

    来自CSDN的Rachel Zhang 4. Improved SAP 算法 本次介绍的重头戏.通常的 SAP 类算法在寻找增广路时总要先进行 BFS,BFS 的最坏情况下复杂度为 O(E),这样使得 ...

随机推荐

  1. win7系统如何恢复administrator用户

    默认情况下,administrator用户是禁用的. 要恢复的话,右键单击我的电脑 管理-->本地用户和组-->用户-->右键属性 把"账户已禁用"前的选择符号去 ...

  2. 第19讲- UI组件之_Button、checkbox、radio

    第19讲 UI组件之_Button.checkbox.radio 四.按钮Button Button继承自TextView,间接继承自View.当用户对按钮进行操作的时候,触发相应事件,如点击,触摸. ...

  3. Bootstrap--本地安装使用

    1.到官网下载:http://v2.bootcss.com 2.下载后是一个压缩文件,把它放在相应的工作目录下,然后解压. 3.新建一个测试文件,然后导入两个文件.

  4. Collections.sort()

    Comparator是个接口,可重写compare()及equals()这两个方法,用于比价功能:如果是null的话,就是使用元素的默认顺序,如a,b,c,d,e,f,g,就是a,b,c,d,e,f, ...

  5. 全响应跨设备的Zoomla!逐浪CMS2 x2.0正式公布

    2014年是中国互联网的重要一年,京东上市.聚美优品领衔创业风范,小米进军国际化.滴滴快的锋火争雄. 作为中国互联网的中间力量,Zoomla!逐浪软件团队坚守信念,始终以WEB开发和科研创新为己任,并 ...

  6. VMware vSphere 5.5的12个更新亮点(3)

    端口镜像 有时有必要捕捉网络中的数据包来追踪问题.最新版本的vSphere包括一个增强版的开源数据包分析器tcpdump和一些镜像端口的选项以捕捉各种场所的流量.您可以捕获虚拟网卡,虚拟交换机,以及主 ...

  7. Windows CMD命令之tasklist及taskkill

    Tasklist介绍 Tasklist"是 winxp/win2003/vista/win7/win8下的命令,用来显示运行在本地或远程计算机上的所有进程,带有多个执行参数. 使用格式 ta ...

  8. Android学习之Activity之间的数据传递

    Activity与Activity之间很多情况下都需要进行数据的传递,下面就用几个简单的例子来看一下. (一).一个Activity启动另一个Activity并将数据传递到这个Activity当中 思 ...

  9. oracle登录错误(ORA-01033:ORACLE initialization or shutdown in progress

    在网上查找出现这种错误的原因一般是因为删除数据库 安装文件下的某个文件造 成的, 但是在我们的服务器上是因为 机子重启(意外断电)了一下就造 成这样的错误,不过解决办法是一样的,下面贴上解决方案 解决 ...

  10. silverlight .net后台 设置visifire控件图表样式 属性说明

    .net后台 代码: 如图 Chart chart = new MyCharts();  //图表            //chart.Watermark = false;  //没好使       ...