自从Snowdrop开始参加ACM的比赛,就一发不可收拾的爱上了它。每次他读到一篇文章,都希望能在里面找到最多的ACM,不论大小写。首先,我们可以定义一篇文章就是一串字符,设它为S,其中每个字符为Si。每次Snowdrop都会在文章中找到三个字符Si, Sj, Sk (i < j < k) 并且Si = ‘a’或’A’, Sj = ‘c’或’C’, Sk = ‘m’或’M’,然后他会划掉这三个字符,得到一个ACM,并再在文章里找。划掉的不再计算。
Snowdrop想知道他最后能得到多少个ACM,你能帮帮他么?
Input
首先输入一个T表示测试样例数(T <= 1500)
然后T行,每行代表一篇文章(只包含大小写字母)
题目保证字符串总长度不超过200000,每篇文章字符串长度不超过100000
Output
按照描述输出,结尾换行
Sample Input
2 aCmCCCAcm AMMMCM
Sample Output
2 1
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <queue>
# include <vector>
# include <cmath>
# define LL long long
# define INF 0x3f3f3f3f
using namespace std;
int main(void)
{
int tes, i, t1, t2, ans;
string s;
scanf("%d", &tes);
while (tes--){
cin>>s;
t1 = t2 = ans = 0;
for (i = 0; s[i]!= '\0'; i++){
if (s[i] == 'a' || s[i] == 'A') t1++;
else if ((s[i] == 'c' || s[i] == 'C') && t1) t1--, t2++;
else if ((s[i] == 'm' || s[i] == 'M') && t2) t2--, ans++;
}
cout<<ans<<endl;
}
return 0;
}