1093 Count PAT's(25 分)

#include
#include
#include
using namespace std;
string s;
const int maxn = 1e6 + 10;
const int mod = 1000000007;
int leftP[maxn];
long long ans;
int main()
{
    getline(cin, s);
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'P')leftP[i] = 1;
        if (i)leftP[i] += leftP[i - 1];
    }
    int rightT = 0;
    for (int i = s.length() - 1; i >= 0; i--)
    {
        if (s[i] == 'T')rightT++;
        if (s[i] == 'A')ans = (ans + leftP[i] * rightT) % mod;
    }
    printf("%lld", ans);
    return 0;
}

你可能感兴趣的:(1093 Count PAT's(25 分))