Colorful Lecture Note(手工栈)

时间:2023-12-09 17:13:55

题目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>*/