A1093 Count PAT's

The string APPAPT contains two PAT’s as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.
Now given any string, you are supposed to tell the number of PAT’s contained in the string.

Input Specification:

Each input file contains one test case. For each case, there is only one line giving a string of no more than 10^5^ characters containing only P, A, or T

Output Specification:

For each test case, print in one line the number of PAT‘s contained in the string. Since the result may be a huge number, you only have to output the result moded by 1000000007.

Sample Input:

1
APPAPT

Sample Output:

1
2

Code

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
#include 
#include
#include
using namespace std;
const int MAXN = 100010;
const int MOD = 1000000007;
int main(){
int i, j;
char str[MAXN];
int left_P[MAXN] = {0};
int right_T[MAXN] = {0};
gets(str);
int len = strlen(str);
for (i=0,j=len-1;i
if(i>0) left_P[i] = left_P[i - 1];
if(j1];

if(str[i]=='P') left_P[i]++;
if(str[j]=='T') right_T[j]++;
}
int count = 0;
for (i=0;i
if(str[i]=='A')
count = (count+left_P[i]*right_T[i])%MOD;
}
printf("%d\n", count);
return 0;
}
丨fengche丨 wechat
来找我聊天吧~
-------------本文结束感谢您的阅读-------------