hihocoder#1103 栈

#include<iostream>  
#include<string>  
#include<string.h>
#include<algorithm>  
#include<fstream>
#include<stack>
#include<map>
using namespace std;  
#define lch(i) ((i)<<1)  
#define rch(i) ((i)<<1|1)  
#define sqr(i) ((i)*(i))  
#define pii pair<int,int>  
#define mp make_pair  
#define FOR(i,b,e) for(int i=b;i<=e;i++)  
#define FORE(i,b,e) for(int i=b;i>=e;i--)  
#define ms(a)   memset(a,0,sizeof(a))  
const int maxnum =100003;
const  int  INF = 10000;

stack<string> color;
map<string,int> num;

int main()    
{  
#ifdef _DEBUG_
    fstream fin("G:/1.txt");
#else
#define fin cin
#endif
    char text[1000];
    num["red"]=0;
    num["yellow"]=0;
    num["blue"]=0;
    gets(text);
    int size = strlen(text);
    FOR(i,0,size-1){
        if(text[i]==' ')continue;
        if(text[i]=='<'){
            if(text[i+1]=='/'){
                i++;
                color.pop();
                if(text[i+1]=='r')
                    i+=4;
                else if(text[i+1]=='b')
                    i+=5;
                else
                    i+=7;
                continue;
            }
            if(text[i+1]=='r'){
                color.push("red");
                i+=4;
            }else if(text[i+1]=='b'){
                color.push("blue");
                i+=5;
            }else{
                color.push("yellow");
                i+=7;
            }
            continue;
        }
        if(!color.empty())
            num[color.top()]++;
    }
    cout<<num["red"]<<' '<<num["yellow"]<<' '<<num["blue"]<<endl;



    return 0;  
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值