-
Notifications
You must be signed in to change notification settings - Fork 0
/
1093.cpp
41 lines (39 loc) · 834 Bytes
/
1093.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
#include <cstdio>
#include <cstring>
char input[100001];
int mod = 1000000007;//此题输出要求对此数取模
int main(){
scanf("%s", input);
int length = strlen(input);
int lefthasP[length];
memset(lefthasP, 0, sizeof(lefthasP));
if(input[0] == 'P'){
lefthasP[0] = 1;
}
for(int i=1; i<length; i++){
if(input[i] == 'P'){
lefthasP[i] = lefthasP[i-1] + 1;
}
else{
lefthasP[i] = lefthasP[i-1];
}
}
int righthasT[length], ans = 0;
memset(righthasT, 0, sizeof(righthasT));
if(input[length-1] == 'T'){
righthasT[length-1] = 1;
}
for(int i=length-2; i>0; i--){
if(input[i] == 'T'){
righthasT[i] = righthasT[i+1] + 1;
}
else if(input[i] == 'A'){
righthasT[i] = righthasT[i+1];
ans = (lefthasP[i-1]*righthasT[i+1]+ans)%mod;
}
else{
righthasT[i] = righthasT[i+1];
}
}
printf("%d", ans);
}