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)