Colorful lecture Note (manual stack)

Source: Internet
Author: User

Topic 1:colorful Lecture Note time limit: 10000ms single point time limit: 1000ms memory limit: 256MB description

Little Hi is writing a algorithm lecture note for Little Ho. The note more comprehensible, Little Hi tries to color some of the text. Unfortunately Little Hi is the using a plain (black and white) text editor. So he decides to tag the text which should is colored for now and color them later when he had a more powerful software su Ch as Microsoft Word.

There is 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> in the beginning an D </COLOR> at the end where COLOR is one of the "red", "yellow" or "blue".

The tag pairs may overlapped only if one pair is completely inside the other pair. Text is colored by the nearest surrounding tag. For example, Little Hi would no 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 is not counted) is colored red, yellow and blue.

Input

Input contains one line:the text with color tags. The length is no more than 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
Note: You need to use get to read spaces.
#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 namespacestd;Const intinf=0x3f3f3f3f;Const Doubleeps=1e-Ten;Const DoublePi=acos (-1.0);#defineMAXN 1100structsta{CharWORD[MAXN]; intCNT =0;}; Sta sta[ -];Chara[ -];intMain () {gets (a); {        intK =1; intCnt1 =0; intCnt2 =0; intCnt3 =0; intJ;  for(inti =0; A[i]! =' /'; i++)        {            if(A[i] = =' ')                Continue; intK1 =0; intFlag =0; if(a[i]=='<') {k++;  for(j = i+1; A[J]! ='>'; J + +)                {                    if(a[j]=='/') Flag=1; Sta[k].word[k1++] =A[j]; } STA[K].WORD[K1]=' /'; I=J; if(flag) {if(strcmp (sta[k-1].word,"Yellow")==0) Cnt1+ = sta[k-1].cnt; if(strcmp (sta[k-1].word,"Blue")==0) Cnt2+ = sta[k-1].cnt; if(strcmp (sta[k-1].word,"Red")==0) Cnt3+ = sta[k-1].cnt; Sta[k-1].cnt = sta[k].cnt =0; K=k-2; }                Continue; } sta[k].cnt++; } printf ("%d%d%d\n", Cnt3,cnt1,cnt2); }    return 0;}/*<yellow>aaa<blue>bbb </blue>ccc</yellow>dddd<red>abc</red>*/

Colorful lecture Note (manual stack)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.