Description title
string APPAPT
contains two words PAT
,
- The first
PAT
is the first2
positionP
, the first4
positionA
, the first6
positionT
; - The second
PAT
is the first3
placeP
, first4
placeA
, first6
placeT
.
Given a string, how many can be formed in total PAT
?
Input format
input single line comprising a string of not more than 10 . 5 , contains only P
, A
, T
three kinds of letters.
Output format
Output how many characters are contained in a given string in one line PAT
.
Since the result may be relatively large, only the result of taking the remainder of 1000000007 is output.
Enter the sample
APPAPT
Sample output
2
Problem solution
mathematics:
解题思路
:
- For each
A
, it can be configuredPA
a number of which depends on all the previousP
number. - For each
T
, it can be configuredPAT
a number of which depends on all the previousPA
number.
#include <iostream>
using namespace std;
typedef long long LL;
const int mod = 1e9 + 7;
int main()
{
string s;
cin >> s;
LL P = 0, PA = 0, PAT = 0;
for (int i = 0; i < s.size(); i ++)
if(s[i] == 'P') P ++;
else if(s[i] == 'A') PA += P;
else PAT = (PAT + PA) % mod;
cout << PAT << endl;
return 0;
}