Input formats:
Input single line comprising a string of not more than 1 contains only P
, A
, T
three kinds of letters.
Output formats:
Output reference number contained in the string line PAT
. As a result may be relatively large, only the output of 1,000,000,007 take the results of the remainder.
Sample input:
APPAPT
Sample output:
2
#include <stdio.h> #define LIM 1000000007 int main() { int P = 0, PA = 0, PAT = 0; char c; while((c = getchar()) != '\n') { if(c == 'P') P++; if(c == 'A') PA = (PA + P) ; if(c == 'T') PAT = (PAT + PA) % LIM; } printf("%d", PAT); return 0; }
Given a string of length n in the "PAT" the number is sum, the number of how many "PAT" new strings if added after a character in the string of would it be?
If the character is added to 'P', the number of new string "PAT" does not change.
If the characters are added as 'A', the number of new string "PAT" does not change.
If the characters are added as 'T', the number of new string "PAT" may vary. While the number of changes because of the added 'T' constitutes a new "PAT". Want to know the number of "PAT" the new constitution, you need to know the number of "PA" old string, because the old string number "PA" is equal to the number of new constitution "PAT" is. I.e., the number of new string "PAT" old = number of the string "PA" in the old string + "PAT" a.
Similarly, the face 'A' new string 'PA' = the number of the old string 'P' + the number of old string 'PA' number.