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
1≤n≤2×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;
}