/
B2.cpp
112 lines (102 loc) · 1.44 KB
/
B2.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#define DEBUG 1
/**
* File : B2.cpp
* Author : Kazune Takahashi
* Created : 2019-6-2 21:39:22
* Powered by Visual Studio Code
*/
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
/*
void Yes()
{
cout << "Yes" << endl;
exit(0);
}
void No()
{
cout << "No" << endl;
exit(0);
}
*/
/*
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
*/
// const ll MOD = 1000000007;
string S;
vector<vector<int>> V;
ll count(vector<int> W)
{
ll ans = 0;
reverse(W.begin(), W.end());
int t = 0;
for (auto x : W)
{
if (x == 1)
{
t++;
}
else
{
ans += t;
}
}
return ans;
}
int main()
{
cin >> S;
int N = S.size();
S = S + "X";
vector<int> W;
for (auto i = 0; i < N; i++)
{
if (S[i] == 'A')
{
W.push_back(0);
}
else if (S[i] == 'B' && S[i + 1] == 'C')
{
W.push_back(1);
i++;
}
else
{
if (!W.empty())
{
V.push_back(W);
}
W.clear();
}
}
if (!W.empty())
{
V.push_back(W);
}
ll ans = 0;
for (auto W : V)
{
ans += count(W);
}
cout << ans << endl;
}