1093. Count PAT's (25)
#include <iostream>
#include <string.h>
using namespace std;
char s[100010];
int main()
{
gets(s);
int i, len = strlen(s);
long long pcount = 0, acount = 0, tcount = 0;
char ch;
for(i = 0; i < len; i++)
{
ch = s[i];
if(ch == 'T')
{
tcount++;
}
}
long long res = 0;
for(i = 0; i < len; i++)
{
ch = s[i];
if(ch == 'T')
{
tcount--;
if(tcount == 0)
{
break;
}
}
else if(ch == 'P')
{
pcount++;
}
else
{
res += pcount * tcount;
}
}
printf("%lld\n", res % 1000000007);
system("pause");
return 0;
}
浙公网安备 33010602011771号