PAT 1093. Count PAT's

CODE:

#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;

const int MOD=1000000007;
const int N=1e5;

char s[N+5];

int main()
{
    while(scanf("%s",s)==1)
    {
        LL p=0;
        LL pa=0;
        LL pat=0;
        int len=strlen(s);
        for(int i=0;i<len;i++)
        {
            if(s[i]=='P')
            {
                p++;
            }
            if(s[i]=='A')
            {
                pa=pa+p;
            }
            if(s[i]=='T')
            {
                pat=pat+pa;
            }
        }
        printf("%d\n",pat%MOD);
    }
    return 0;
}


你可能感兴趣的:(水)