2019CCPC湖南全国邀请赛(广东省赛、江苏省赛) E Hello xtCpc

博客围绕在给定的大小写字母字符串中查找尽可能多的“gdCpc”序列展开,同一位置字母只能用一次。介绍了输入输出格式,给出示例,还提及解题思路为前缀和,将其分成 c,xt,xtC,xtCp,xtCpc 。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description

You have a string of lowercase letters.You need to find as many sequence “gdCpc” 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

 思路:前缀和,分成 c,xt,xtC,xtCp,xtCpc

#include<cstdio>
#include<cstring>
using namespace std;
char a[205000];
int falg=1;//xtCpc

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%s",a);
        /*for(int i=0;i<40000;i++) a[i]='x';
        for(int i=40000;i<80000;i++) a[i]='t';
        for(int i=80000;i<120000;i++) a[i]='C';
        for(int i=120000;i<160000;i++) a[i]='p';
        for(int i=160000;i<200000;i++) a[i]='c';
        a[200000]='\0';*/
        int sum[10]={0},s=0;
        for(int i=0;a[i]!='\0';i++)
        {
            if(a[i]=='x') sum[1]++;
            else if(a[i]=='t')
            {
                if(sum[1]>=1)
                {
                    sum[1]--;
                    sum[2]++;
                }
            }
            else if(a[i]=='C') {
                if(sum[2]>=1)
                {
                    sum[2]--;
                    sum[3]++;
                }
            }
            else if(a[i]=='p') {
                if(sum[3]>=1)
                {
                    sum[3]--;
                    sum[4]++;
                }
            }
            else if(a[i]=='c')
            {
                if(sum[4]>=1)
                {
                    sum[4]--;
                    sum[5]++;
                }
            }
        }
        //scanf("%s",a);
        printf("%d\n",sum[5]);
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值