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. ACM学习历程—HDU 5073 Galaxy(数学)

    Description Good news for us: to release the financial pressure, the government started selling gala ...

  2. bzoj 2342: 双倍回文 回文自动机

    题目大意: 定义双倍回文串的左一半和右一半均是回文串的长度为4的倍数的回文串 求一个给定字符串中最长的双倍回文串的长度 题解: 我们知道可以简单地判定以某一点结尾的最长回文串 我们知道可以简单地判定以 ...

  3. 卸载DCOS

    再次安装,已经是隔了两天,我打算换一台机器作为boot机器,但是发现报错,告知部署设备已经安装了dcos:看来需要卸载:uninstall-master.sh /opt/mesosphere/bin/ ...

  4. android开发 解析服务器端xml文件数据存储到android客户端SQLite数据库

    以下面xml文件为例对其解析(假设此xml就在服务器端Server项目下的servlet包下的MenuServlet文件的输出流中): <?xml version="1.0" ...

  5. docker里安装ubuntu

    使用 Ubuntu 官方镜像 Ubuntu 相关的镜像有很多,这里使用 -s 10 参数,只搜索那些被收藏 10 次以上的镜像 $ docker search -s 10 ubuntu NAME DE ...

  6. 树莓派 Learning 003 --- GPIO 001 --- 点亮LED

    树莓派 Learning 003 - GPIO 001 - 点亮LED 我的树莓派型号:Raspberry Pi 2 Model B V1.1 装机系统:NOOBS v1.9.2 树莓派 Learni ...

  7. 【机器学习】主题模型(二):pLSA和LDA

      -----pLSA概率潜在语义分析.LDA潜在狄瑞雷克模型 一.pLSA(概率潜在语义分析) pLSA:    -------有过拟合问题,就是求D, Z, W pLSA由LSA发展过来,而早期L ...

  8. 6.7 安装ant

    准备好安装包: 安装vim: 解压: tar -xzvf apahce-ant-1.10.1-bin.tar.gz 这里,我将apache-ant-1.10.1-bin.tar.gz复制并解压到了/h ...

  9. Qt5编译项目出现GL/gl.h:No such file or directory错误

    编译在Ubuntu12.04下安装了Qt5.1.1,在编译工程的时候出现了如下错误:“GL/gl.h:No such file or directory”,查了一下资料发现这个问题由于系统中没有安装O ...

  10. chrome - Vimium 插件超级方便快捷键

    Vimium插件作用 安装后,可以用定义好的快捷键操作浏览器,好用到爆粗口 下载地址 https://chrome.google.com/webstore/detail/vimium/dbepggeo ...