-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMOZHSLM.cpp
More file actions
42 lines (37 loc) · 739 Bytes
/
Copy pathMOZHSLM.cpp
File metadata and controls
42 lines (37 loc) · 739 Bytes
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
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
int n = s.size();
int pre[n], post[n];
int cnt = 0;
for(int i = 0; i < n; i++)
{
pre[i] = cnt;
if(s[i] == 's')
cnt++;
}
cnt = 0;
for(int i = n-1; i >=0; i--)
{
post[i] = cnt;
if(s[i] == 's')
cnt++;
}
long long ans = 0;
for(int i = 0; i < n; i++)
{
if(s[i] == 'm')
{
ans += (long long) pre[i] * post[i];
}
}
cout<<ans<<endl;
}
}