-
Notifications
You must be signed in to change notification settings - Fork 0
/
blkek.cpp
37 lines (37 loc) · 930 Bytes
/
blkek.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int tests;
scanf("%d", &tests);
while(tests--) {
char str[2001];
scanf("%s", str);
int len = strlen(str);
vector<int> prev;
vector<int> post;
int prevCount = 0;
for(int i=0;i<len;++i) {
if(str[i] == 'K') {
prevCount++;
} else if(str[i] == 'E') {
prev.push_back(prevCount);
}
}
int postCount = 0;
for(int i=len-1;i>=0;--i) {
if(str[i] == 'K') {
postCount++;
} else if(str[i] == 'E') {
post.push_back(postCount);
}
}
long long sum = 0;
for(int i=0;i<prev.size();++i) {
sum += prev[i] * post[prev.size() - i - 1];
}
printf("%lld\n", sum);
}
}