1040 有几个PAT (25分)

#include <string.h>
#include <iostream>
using namespace std;

int main()
{
    long int num=1000000007,count=0,count_p=0,count_t=0;
    char * str=new char[100005];
    cin>>str;
    for(int i=0;i<strlen(str);i++)
    {
        if(str[i]=='T')
            count_t++;
    }
    for(int i=0;i<strlen(str);i++)
    {
        if(str[i]=='P')
            count_p++;
        else if(str[i]=='T')
            count_t--;
        else if(str[i]=='A')
            count+=count_t*count_p;
        count%=num;
    }
    count%=num;
    cout<<count<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/QRain/p/12252467.html