The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.

Now given any string, you are supposed to tell the number of PAT's contained in the string.

Input Specification:

Each input file contains one test case. For each case, there is only one line giving a string of no more than 105 characters containing only P, A, or T.

Output Specification:

For each test case, print in one line the number of PAT's contained in the string. Since the result may be a huge number, you only have to output the result moded by 1000000007.

Sample Input:

APPAPT

Sample Output:

2

#include<iostream>
using namespace std;
int main(){
string s;
getline(cin,s);
/* 用long long int 防止sum过大,p[]数组中p[i]表示下标为i的A前面有p[i]个P。
sp为目前的P的数量,st表示目前T的数量 */
long long int p[s.size()]={0},sp=0,st=0,sum=0;
/* 先正着遍历一遍用sp记录目前碰到P的数量,一旦遇到A
就把当前P的数量储存到p[i]中,这样每个A前的P的数量就知道了*/
for(int i=0;i<s.size();i++){
if(s[i]=='P')
sp++;
if(s[i]=='A')
p[i]=sp;
}
/* 再倒着遍历一遍,用st记录碰到的 T的数量,当遇到A时
就把p[i](即A前P的数量)乘以st(即该A后的T的数量)加到sum上*/
for(int i=s.size()-1;i>=0;i--){
if(s[i]=='T')
st++;
if(s[i]=='A')
sum+=st*p[i];
}
cout<<sum%1000000007<<endl;
return 0;
}

PAT 1093. Count PAT's的更多相关文章

  1. PAT 1093 Count PAT's[比较]

    1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...

  2. PAT甲级——1093 Count PAT's (逻辑类型的题目)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分)   ...

  3. PAT (Advanced Level) Practise - 1093. Count PAT's (25)

    http://www.patest.cn/contests/pat-a-practise/1093 The string APPAPT contains two PAT's as substrings ...

  4. 1093. Count PAT's (25)

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  5. 1093. Count PAT's

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  6. 1093. Count PAT’s (25)-统计字符串中PAT出现的个数

    如题,统计PAT出现的个数,注意PAT不一定要相邻,看题目给的例子就知道了. num1代表目前为止P出现的个数,num12代表目前为止PA出现的个数,num123代表目前为止PAT出现的个数. 遇到P ...

  7. 1093 Count PAT's(25 分)

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  8. 【PAT甲级】1093 Count PAT's (25 分)

    题意: 输入一行由大写字母'P','A','T',组成的字符串,输出一共有多少个三元组"PAT"(相对顺序为PAT即可),答案对1e9+7取模. AAAAAccepted code ...

  9. PAT甲级 1093 Count PAT‘s (25 分) 状态机解法

    题目 原题链接 The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the ...

随机推荐

  1. Luogu4198 楼房重建

    https://zybuluo.com/ysner/note/1124880 题面 带修改的区间维护最大斜率. 题面 解析 用线段树区间维护斜率. 考虑如何向上合并. 左半段一定有贡献. 如果左半段的 ...

  2. bzoj2752

    线段树+概率 今天这道题爆零了,奥妙重重. 其实我们可以把式子化成这样:sigma((i-l+1)*(r-i+1)*ai) 这里r减了1 然后展开,(1-l)*(r+1)*ai+(r+l)*i*ai- ...

  3. jQuery Validate插件实现表单强大的验证功能

    转自:http://www.jb51.net/article/76595.htm jQuery Validate插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同时提供了一个用来编写用户自 ...

  4. 【转载】HashMap底层实现原理及面试问题

    ①HashMap的工作原理 HashMap基于hashing原理,我们通过put()和get()方法储存和获取对象.当我们将键值对传递给put()方法时,它调用键对象的hashCode()方法来计算h ...

  5. 如何获取<a>标签的Id

    案例: <a id='213' href='javascript:void(0);'onclick=DealFun(this.Id);>删除</a> 解决方案: functio ...

  6. 【洛谷3648/BZOJ3675】[APIO2014]序列分割(斜率优化DP)

    题目: 洛谷3648 注:这道题洛谷3648有SPJ,要求输出方案.BZOJ3675数据组数较多但不要求输出方案. 分析: 这可能是我第三次重学斜率优化了--好菜啊 这道题首先一看就是个DP.稍微推一 ...

  7. 题解报告:hdu 2516 取石子游戏(斐波那契博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2516 Problem Description 1堆石子有n个,两人轮流取.先取者第1次可以取任意多个, ...

  8. Spring Boot (25) RabbitMQ消息队列

    MQ全程(Message Queue)又名消息队列,是一种异步通讯的中间件.可以理解为邮局,发送者将消息投递到邮局,然后邮局帮我们发送给具体的接收者,具体发送过程和时间与我们无关,常见的MQ又kafk ...

  9. Android项目实战_手机安全卫士系统加速

    ## 1.本地数据库自动更新的工作机制1. 开启一个服务,定时访问服务器2. 进行版本对比,如果最新版本比较高,获取需要更新的内容3. 将新内容插入到本地数据库中 ## 2.如何处理横竖屏切换1. 指 ...

  10. jQuery与js的区别,并有基本语法详解,

    通过过一下对比,我们能很清楚的发现jquery与js的区别,运用jquery能大量减少代码量,不过js里面关于时间的setinterval和settimeout只能用js <script src ...