-
Notifications
You must be signed in to change notification settings - Fork 0
/
ac.cpp
46 lines (38 loc) · 891 Bytes
/
ac.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
38
39
40
41
42
43
44
45
46
//created by tony on 7/23/2021.
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
ll ans = 0;
int l;
cin >> l;
string line;
cin >> line;
ll amta = 0;
ll amtc = 0;
char saved = line[0];
while (!line.empty()) {
if (saved == 'c' && line[0] == 'a')
{
ans += amta*amtc;
amtc = 0;
}
if (line[0] == 'a')
amta++;
else
amtc++;
saved = line[0];
line = line.substr(1);
}
ans += amta*amtc;
cout << ans << "\n";
}
system("PAUSE");
return 0;
}