Hello GDCPC

Problem Description

You have a string of lowercase letters.You need to find as many sequence “xtCpc” as possible.But letters in the same position can only be used once。

Input

The input file contains two lines.

The first line is an integer n show the length of string.(1≤n≤2×105)

The second line is a string of length n consisting of lowercase letters and uppercase letters.

Output

The input file contains an integer show the maximum number of different subsequences found.

Sample Input

10 

gdCgdCpcpc

Sample Output

2

题意:找串中出现xtCpc(不一定连续)的最大个数。

思路:找一个数组(4个数x1,x2,x3,x4)分别记录x、t、 C、 p、 c的个数,数量加一当且仅当该字符前面的数量大于当前字符的数量,如果遇到c,就将数量都减一,ans++。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=2e5+10;
int a[100];
char s[M];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        mem(s,0);
        scanf("%s",s);
        mem(a,0);
        int ans=0;
        for(int i=0; i<n; i++)
        {
            if(s[i]!='x'&&s[i]!='t'&&s[i]!='C'&&s[i]!='p'&&s[i]!='c')
                continue;
            if(s[i]=='x')
                s[i]='1';
            else if(s[i]=='t')
                s[i]='2';
            else if(s[i]=='C')
                s[i]='3';
            else if(s[i]=='p')
                s[i]='4';
            else if(s[i]=='c')
                s[i]='5';
            if(a[s[i]-1]||s[i]=='1'){
                if(a[s[i]-1]>a[s[i]]||s[i]=='1')
                    a[s[i]]++;
                if(s[i]=='5'){
                    for(int j='1'; j<='5'; j++)
                        a[j]--;
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
    }

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值