[HDU6536] Hello XTCPC

题目
题意:给一个字符串,寻找最多个数“xtCpc”的子串,有大小写区别。
思路:对于队列不太熟悉,一开始用数组,自己造的数据死活过不了,交了两次也就没写了。用队列保存每个字母出现的下标,然后由x开始检索,查找符合条件的下标大于前一个字母下标的对象,不符合条件的,后面的也不可能成立,于是pop。查完到‘c’的时候,答案+1;如果超出就结束。

/*
 @Author : Rye Wang
 @Version : 1.0
 @E-mail : Rye10000010000@hotmail.com
 @Site: Rye1024.gitee.io
 @Time : 2020-05-24-19.05.11
*/
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define dbug cout << "Where?" << endl;

int main()
{
    int t;
    string s;
    while(cin >> t >> s)
    {
        queue<int> x;
        queue<int> t;
        queue<int> C;
        queue<int> p;
        queue<int> c;
        while( ! x.empty())
            x.pop();
        while( ! t.empty())
            t.pop();
        while( ! C.empty())
            C.pop();
        while( ! p.empty())
            p.pop();
        while( ! c.empty())
            c.pop();
        for(int i = 0; i < s.size(); i++)
        {
            if(s[i] == 'x') x.push(i);
            else if(s[i] == 't') t.push(i);
            else if(s[i] == 'C') C.push(i);
            else if(s[i] == 'p') p.push(i);
            else if(s[i] == 'c') c.push(i);
        }
        int ans = 0;
        while(x.size()){
            int pos = x.front();
            x.pop();
            while(t.size() && t.front() < pos) t.pop();
            if(t.empty()) break;
            pos = t.front();
            t.pop();
            while(C.size() && C.front() < pos) C.pop();
            if(C.empty()) break;
            pos = C.front();
            C.pop();
            while(p.size() && p.front() < pos) p.pop();
            if(p.empty()) break;
            pos = p.front();
            p.pop();
            while(c.size() && c.front() < pos) c.pop();
            if(c.empty()) break;
            pos = c.front();
            c.pop();
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值