有几个PAT(25)
时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)
题目描述
字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位§,第4位(A),第6位(T);第二个PAT是第3位§,第4位(A),第6位(T)。
现给定字符串,问一共可以形成多少个PAT?
输入描述:
输入只有一行,包含一个字符串,长度不超过105,只包含P、A、T三种字母。
输出描述:
在一行中输出给定字符串中包含多少个PAT。由于结果可能比较大,只输出对1000000007取余数的结果。
输入例子:
APPAPT
输出例子:
2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <climits>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#define N 100000+5
#define MO 1000000007
using namespace std;
int main(){
char input[N];
int num[3]={0};
cin>>input;
int len=strlen(input);
for(int i=0;i<len;i++){
switch(input[i]){
case 'P':num[0]++;break;
case 'A':num[1]+=num[0];break;
case 'T':num[2]+=num[1];num[2]%=MO;break;
}
}
cout<<num[2];
return 0;
}