zoukankan      html  css  js  c++  java
  • Colorful Lecture Note(手工栈)

    题目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-10;
    const double PI=acos(-1.0);
    #define maxn 1100
    struct Sta
    {
        char word[maxn];
        int cnt = 0;
    };
    Sta sta[100];
    char a[1200];
    int main()
    {
        gets(a);
        {
            int k = 1;
            int cnt1 = 0;
            int cnt2 = 0;
            int cnt3 = 0;
            int j;
            for(int i = 0; a[i] != ''; i++)
            {
                if(a[i] == ' ')
                    continue;
                int k1 = 0;
                int flag = 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
    ", cnt3,cnt1,cnt2);
        }
        return 0;
    }
    /*<yellow>aaa<blue>bbb  </blue>ccc</yellow>dddd<red>abc</red>*/
     
  • 相关阅读:
    ubuntu17.10 源
    _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed
    shell | crontab 定时任务
    python将负数转为16进制无符号数
    vooya --- a YUV player and a generic raw data player
    clion 查看代码 多次查看后如何一步一步回退到最初查看的代码位置
    Unity3d XmlException: Text node cannot appear in this state的方案
    Unity2017灯光烘焙知识点
    unity加载ab后,场景shader不起效问题(物件表现黑色)
    BMFont制作美术字体
  • 原文地址:https://www.cnblogs.com/ZP-Better/p/5040981.html
Copyright © 2011-2022 走看看