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;
}

 

posted @ 2020-02-02 15:51  QRain  阅读(119)  评论(0编辑  收藏  举报