leafee 最近爱上了 abb 型语句,比如“叠词词”、“恶心心” leafee 拿到了一个只含有小写字母的字符串,她想知道有多少个 "abb" 型的子序列? 定义: abb 型字符串满足以下条件:
字符串长度为 3 。 字符串后两位相同。 字符串前两位不同。
来源:https://ac.nowcoder.com/acm/contest/71300/E
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,sum=0;
cin >> n;
string str;
cin >> str;
unordered_map<char, int> omap;
for(string::iterator j = str.begin();j!=str.end();j++){
omap[*j]++;
}
for(string::iterator i = str.begin();i!=str.end();i++){
char ok = *i;
omap[*i]-1!=0?omap[*i]--:1;
for(unordered_map<char, int>::iterator j = omap.begin();j!=omap.end();j++){
if((*j).first!=*i){
sum += (((*j).second*((*j).second-1))/2);
}
}
}
cout << sum;
return 0;
}