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

package hiho_75;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack; public class Main { public static void main(String[] argv){ Scanner in = new Scanner(System.in);
String source = in.nextLine();
in.close();
Stack<Integer> color = new Stack<Integer>();
char[] s = source.toCharArray();
int l = s.length; int[] out = new int[3];
ArrayList<Integer> temp = new ArrayList<Integer>();
ArrayList<Integer> sp_temp = new ArrayList<Integer>();
int space_count=0; //....预处理
for(int i=0; i<l; i++){
int t = -i;
char k = s[i];
if(k=='<'){
if(s[i+1]=='/')
temp.add(t);
else
temp.add(i);
continue;
}
if(k=='>'){
temp.add(i); sp_temp.add(space_count); space_count=0;
continue;
} if(k==' ')
space_count++;
} //......栈处理
int L = temp.size();
int space_n=1;
int[] link = new int[L-1];
for(int i=0; i<L-1; i++){
int j = (int) temp.get(i);
int k = (int) temp.get(i+1);
if(i%2==0){ if(j>=0){
int p = k-j;
if(p==7)
link[i]=-1;
else{
if(p==5)
link[i]=-2;
else
link[i]=-3;
}
}
else{
j=-j;
int p = k-j;
if(p==8)
link[i]=-4;
else{
if(p==6)
link[i]=-5;
else
link[i]=-6;
} }
}
else{
if(k>0)
link[i]=k-j-1-sp_temp.get(space_n++);
else
link[i]=-k-j-1-sp_temp.get(space_n++); }
} //...选择颜色
int [] count = new int[3];
for(int i=L-2; i>=0; i--){ if(i%2==0){ switch(link[i]){ case -4:
color.push(0); break;
case -5:
color.push(1); break;
case -6:
color.push(2); break;
case -1:
color.pop(); break;
case -2:
color.pop(); break;
case -3:
color.pop(); break; }
}
else{
if(!color.isEmpty()){
int k =(int) color.pop();
color.push(k);
switch(k){
case 0: out[0]=out[0]+link[i]; break;
case 1: out[1]=out[1]+link[i]; break;
case 2: out[2]=out[2]+link[i]; break;
}
}
}
} //...输出结果
System.out.println(out[2]+" "+out[0]+" "+out[1]); }
}

Colorful Lecture Note的更多相关文章

  1. Colorful Lecture Note(手工栈)

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

  2. hihocoder #1103 : Colorful Lecture Note微软苏州校招笔试 1月10日(字符串处理+栈)

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

  3. HihoCoder - 1103 Colorful Lecture Note

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

  4. 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 ...

  5. awesome-nlp

    awesome-nlp  A curated list of resources dedicated to Natural Language Processing Maintainers - Keon ...

  6. Computer Science Theory for the Information Age-4: 一些机器学习算法的简介

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

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

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

  8. CodeForce 517 Div 2. C Cram Time

    http://codeforces.com/contest/1072/problem/C C. Cram Time time limit per test 1 second memory limit ...

  9. Stanford CS20学习笔记

    Lecture Note 2 Tensorboard P3 Data Structures P4 Math Operations P6 Data Types P7 tf native &&am ...

随机推荐

  1. 【读书笔记::深入理解linux内核】内存寻址

    我对linux高端内存的错误理解都是从这篇文章得来的,这篇文章里讲的 物理地址 = 逻辑地址 – 0xC0000000:这是内核地址空间的地址转换关系. 这句话瞬间让我惊呆了,根据我的CPU的知识,开 ...

  2. powerpc平台移植zebra或quagga-0.99.23

    1,先configure  ./configure   --enable-vtysh --disable-bgpd --disable-ripd --disable-ripngd --disable- ...

  3. day41 - 异步IO、协程

    目录 (见右侧目录栏导航) - 1. 前言- 2. IO的五种模型- 3. 协程    - 3.1 协程的概念- 4. Gevent 模块    - 4.1 gevent 基本使用    - 4.2 ...

  4. html 简单学习

    通过记事本,依照以下四步来创建您的第一张网页. 步骤一:启动记事本 如何启动记事本: 开始    所有程序        附件            记事本 步骤二:用记事本来编辑 HTML 在记事本 ...

  5. js复制文字

    一.原理分析 浏览器提供了 copy 命令 ,可以复制选中的内容 document.execCommand("copy") 如果是输入框,可以通过 select() 方法,选中输入 ...

  6. [BZOJ3150][Ctsc2013]猴子 期望dp+高斯消元

    3150: [Ctsc2013]猴子 Time Limit: 20 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 163  Solved: 10 ...

  7. Solr本地服务器搭建及查询

    0.安装solr之前,确保已安装好java8,  java -version 查看是否安装 1.新建本地目录solr1 并 解压两个压缩包文件 .tar.gz .tgz tomcat7 2.将CATA ...

  8. js过滤检测敏感词汇

    html: <textarea rows="10" cols="100" id="myDiv"></textarea> ...

  9. Python全栈开发之1、输入输出与流程控制

    Python简介 python是吉多·范罗苏姆发明的一种面向对象的脚本语言,可能有些人不知道面向对象和脚本具体是什么意思,但是对于一个初学者来说,现在并不需要明白.大家都知道,当下全栈工程师的概念很火 ...

  10. bzoj 1877 最小费用流

    思路:挺裸的费用流,拆拆点就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se sec ...