-
Notifications
You must be signed in to change notification settings - Fork 0
/
1093.cpp
63 lines (54 loc) · 927 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
using namespace std;
#define MAX_LENGTH 100010
char buffer[MAX_LENGTH];
int pindex[MAX_LENGTH];
int aindex[MAX_LENGTH];
int tindex[MAX_LENGTH];
int plength, alength, tlength;
int main()
{
int count = 0;
int ppos = 0, apos = 0, tpos = 0;
cin.getline(buffer, MAX_LENGTH);
for (int i = 0; buffer[i] != '\0'; ++i)
{
switch(buffer[i])
{
case 'P':
pindex[plength++] = i;
break;
case 'A':
aindex[alength++] = i;
break;
case 'T':
tindex[tlength++] = i;
break;
}
}
while (pindex[0] > aindex[apos])
{
++apos;
}
for ( ; apos != alength; ++apos)
{
while (ppos != plength && pindex[ppos] < aindex[apos])
{
++ppos;
}
--ppos;
while (tpos != tlength && aindex[apos] > tindex[tpos])
{
++tpos;
}
if (tpos == tlength)
{
break;
}
count += (ppos+1)*(tlength-tpos);
count %= 1000000007;
}
cout << count << endl;
system("pause");
return 0;
}