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. mysqldump 逻辑备份的正确方法【转】

    1. 利用mysqldump进行逻辑备份 1)全逻辑备份: mysqldump -uxxx -p --flush-logs --delete-master-logs --all-databases & ...

  2. python从2.6.x升级到2.7.x

    [前提] 今日是20171207,目前Linux发行版默认安装的Python版本都是2.6.x,但是这个版本Python已经不再进行维护了. 所以需要将Python做一个升级,到2.7.x [注意] ...

  3. 13.Python3标准库--互联网

    (一)urllib.parse:分解url urllib.parse模块提供了一些函数,可以管理URL以及组成部分 1.解析 from urllib.parse import urlparse ''' ...

  4. HDU 2147 kiki's game(博弈图上找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2147 题目大意:给你一个n*m的棋盘,初始位置为(1,m),两人轮流操作,每次只能向下,左,左下这三个 ...

  5. 完美解决wordpress邮件链接无效的问题

    教程介绍:解决wordpress新用户注册邮件链接无效以及重新设置密码链接无效的问题 解决流程 案例一.用户注册 当用户注册站点时,用户会收到如下注册信: 当用户点击链接时,却发现链接无效: 仔细观察 ...

  6. [你必须知道的.NET]第二十二回:字符串驻留(上)---带着问题思考

    发布日期:2008.8.27 作者:Anytao © 2008 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. 说在,开篇之前 走钢丝的人,在刺激中体验快感.带着问题思考,在问题 ...

  7. 用numpy计算成交量加权平均价格(VWAP),并实现读写文件

    VWAP(Volume-Weighted Average Price,成交量加权平均价格)是一个非常重要的经济学量,它代表着金融资产的“平均”价格.某个价格的成交量越高,该价格所占的权重就越大.VWA ...

  8. AC日记——#2057. 「TJOI / HEOI2016」游戏 LOJ

    #2057. 「TJOI / HEOI2016」游戏 思路: 最大流: 代码: #include <cstdio> #include <cstring> #include &l ...

  9. 一、React Native 搭建开发环境(1)(Mac OS - IOS项目篇)

    React Native是Facebook推出的一个开发IOS和安卓APP的技术.至于更多的详情,这里不再描述,大家可以自行百度它的定义. 原因:由于我想在一台电脑上同时开发IOS和Android两个 ...

  10. Adsafe 导致win10 中窗口错位

    域账号使用,出现上述情况,干掉后一切恢复正常... 还好家里的本地管理员账号使用一切正常,不然又被广告占领了