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 1 characters containing only PA, 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<cstdio>
#include<cstring>
const int maxn = ;
const int MOD = ;
char str[maxn];
int leftNumP[maxn] = {};
int main(){
fgets(str,maxn,stdin);
int len = strlen(str);
for(int i = ; i < len; i++){
if(i > ){
leftNumP[i] = leftNumP[i-];
}
if(str[i] == 'P'){
leftNumP[i]++;
}
}
int ans = ,rightNumT = ;
for(int i = len - ; i >= ; i--){
if(str[i] == 'T'){
rightNumT++;
}else if(str[i] == 'A'){
ans = (ans + rightNumT * leftNumP[i]) % MOD;
}
}
printf("%d\n",ans);
return ;
}

1093 Count PAT's(25 分)的更多相关文章

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

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

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

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

  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 (25)-统计字符串中PAT出现的个数

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

  6. A1093 Count PAT's (25 分)

    一.技术总结 这是一个逻辑题,题目大职意思是可以组成多少个PAT,可以以A为中心计算两边的P和T,然后数量乘积最后相加便是答案. 还有一个注意的是每次相加后记得mod,取余,不要等到最后加完再取余,会 ...

  7. PAT (Advanced Level) 1093. Count PAT's (25)

    预处理每个位置之前有多少个P,每个位置之后有多少个T. 对于每个A,贡献的答案是这个A之前的P个数*这个A之后T个数. #include<cstdio> #include<cstri ...

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

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

  9. pat1093. Count PAT's (25)

    1093. Count PAT's (25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng The strin ...

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

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

随机推荐

  1. CF510E. Fox And Dinner

    CF510E. Fox And Dinner https://codeforces.com/contest/510 分析: 由于\(a_i>2\), 相邻两个数一定一奇一偶,按奇偶建立二分图. ...

  2. bzoj 2732: [HNOI2012]射箭 半平面交

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=2732 题解: 这道题的做法我不想说什么了... 其他题解都有说做法... 即使是我上午做 ...

  3. 【Facebook】等差子序列个数

    题目: 给定一整数数列,问数列有多少个子序列是等差数列. 即对于包含N个数的数列A,A(0),A(1),……,A(N-1),有多少组(P(0),P(1),……,P(k))满足0<=P(0)< ...

  4. Hyperledger fablic 0.6 在centos7环境下的安装与部署

    原文:http://blog.csdn.net/zhaoliang1131/article/details/54617274 Hyperledger Fabric超级账本 项目约定共同遵守的 基本原则 ...

  5. java基础知识(8)---内部类

    内部类:如果A类需要直接访问B类中的成员,而B类又需要建立A类的对象.这时,为了方便设计和访问,直接将A类定义在B类中.就可以了.A类就称为内部类.内部类可以直接访问外部类中的成员.而外部类想要访问内 ...

  6. 超牛 猴子补丁,修改python内置的print

    猴子补丁一般是用于修改三方包或官方包,也可以用来修改自己或者他人的代码. 但也可以用来修改python 语言内置的关键字. 本篇博客修改python最常用的内置print,使你使用print时候,自动 ...

  7. UpdatePanel无刷新

    使用UpdatePanel实现无刷新效果 1. <asp:ScriptManager ID="scriptManger1" ruant="server"& ...

  8. React中state与props介绍与比较

    一.state 1.state的作用 state是React中组件的一个对象.React把用户界面当做是状态机,想象它有不同的状态然后渲染这些状态,可以轻松让用户界面与数据保持一致. React中,更 ...

  9. 面试题: redis面试题 有用 redis详细

    redis面试题目总结 2017-08-25 09:31:02      0个评论    来源:Java仗剑走天涯   收藏   我要投稿   (1)什么是redis? Redis 是一个基于内存的高 ...

  10. 《精通Spring4.X企业应用开发实战》读后感第五章(基于注解的配置)