登录之后查看代码,点此登录账号
#include <stdio.h>
#include <string.h>
typedef long long ll;
ll left[100005];//从左边开始到第i个有多少个T
ll right[100005];//从右边开始到第i个有多少个T
char s[100005];
int main() {
while (scanf("%s", s+1) != EOF) {
int len = strlen(s+1);
for (int i = 1; i <= len; i++) {
if (s[i] == 'T') left[i] = left[i - 1] + 1;
else left[i] = left[i - 1];
}
for (int i = len; i >= 1; i--) {
if (s[i] == 'T') right[i] = right[i + 1] + 1;
else right[i] = right[i + 1];
}
ll sum = 0;
for (int i = 1; i <= len; i++) {//枚举每一个A
if (s[i] == 'A') sum += (left[i] * right[i]);
}
printf("%lld\n", sum);
}
return 0;
}