Hello XTCPC

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。
您有一串小写字母。您需要找到尽可能多的序列“xtCpc”。但是字母在同一个位置只能使用一次。

Input 输入

The input file contains two lines.
输入文件包含两行。

The first line is an integer
第一行是一个整数 n n n 表示字符串的长度。( 1 ≤ n ≤ 2 × 1 0 5 1 \leq n \leq 2 \times 10^5 1n2×105)n show the length of string.(1≤n≤2×105)
第一行是一个整数 , n 显示字符串的长度。 ( 1≤n≤2×105 )

The second line is a string of length n consisting of lowercase letters and uppercase letters.
第二行是长度为 n 的字符串,由小写字母和大写字母组成。

Output 输出

The input file contains an integer show the maximum number of different subsequences found.
输入文件包含一个整数,显示找到的不同子序列的最大数量。

解题思路

先后顺序记录出现次数

Sample Input 示例输入

10
xtCxtCpcpc

Sample Output 示例输出

2

AC代码

#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
	int n;
	while(cin>>n)
	{
		int x=0,t=0,C=0,p=0,c=0;
		s.clear();   
		cin>>s;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='x')	x++;
			else if(s[i]=='t'&&t<x)	t++;
			else if(s[i]=='C'&&C<t)	C++;
			else if(s[i]=='p'&&p<C)	p++;
			else if(s[i]=='c'&&c<p)	c++;	
		}
		cout<<c<<'\n';
	}
	return 0;
 } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值