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>*/
     
  • 相关阅读:
    [Python自学] PyQT5-Web控件、与JavaScript交互
    [Python自学] PyQT5-选项卡窗口、堆栈窗口、停靠窗口、子窗口
    [Python自学] PyQT5-窗口风格、窗口样式、GIF动画、窗口透明
    [Python自学] PyQT5-子线程更新UI数据、信号槽自动绑定、lambda传参、partial传参、覆盖槽函数
    [Python自学] PyQT5-信号与槽
    [Python自学] PyQT5-菜单栏、工具栏、状态栏
    [Python自学] PyQT5-控件拖拽、剪切板
    [Python自学] PyQT5-各种QDialog对话框
    [Python自学] PyQT5-QSpinBox、QSlider控件
    Linux操作系统分析 | 课程学习总结报告
  • 原文地址:https://www.cnblogs.com/ZP-Better/p/5040981.html
Copyright © 2011-2022 走看看