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<cstdio>
#include<iostream>
#include<string.h>
using namespace std;
char str[];
int pnum[] = {, }, tnum[] = {, };
int main(){
long long cntp = , cntt = , ans = ;
scanf("%s", str);
for(int i = ; str[i] != '\0'; i++){
if(str[i] == 'P')
cntp++;
else if(str[i] == 'A')
pnum[i] = cntp;
}
for(int i = strlen(str) - ; i >= ; i--){
if(str[i] == 'T')
cntt++;
else if(str[i] == 'A')
tnum[i] = cntt;
}
for(int i = ; str[i] != '\0'; i++){
if(str[i] == 'A')
ans += tnum[i] * pnum[i];
}
printf("%lld", ans % );
cin >> str;
return ;
}

总结:

1、方法为,统计每个A左边的P个数和右边的T个数,则这个A能组成的PAT即为P个数乘T个数。为避免n^2复杂度,应设置记录数组,在遍历时记录P数和T数。

2、答案要模1000000007。

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

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

  6. 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 ...

  7. PAT 1093. Count PAT's

    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. SQL Server扩充表字段长度,引发的意外KILLED/ROLLBACK

    这一段时间,因为系统升级,新系统产生的数据长度,比原来的数据长度要长,所以说要扩充一下字段长度. ) --修改字段长度sql 在执行的时候,有这样一个情况. 例如Student表的Name字段长度是n ...

  2. linux书籍

    <鸟哥私房菜-基础版> <实战LINUX_SHELL编程与服务器管理> <LINUX命令行与SHELL脚本编程大全第2版].布卢姆.扫描版> <Linux初学 ...

  3. 《Linux内核分析》第六周学习笔记

    <Linux内核分析>第六周学习笔记 进程的描述和创建 郭垚 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/co ...

  4. ros-安装

    1.安装了ubuntu for ros. 运行评论下边那条命令: 2.rtabamp 3.准备安装机器人导航仿真系统:https://blog.csdn.net/wangchao7281/articl ...

  5. 第二个spring, 第7天

    陈志棚:成绩的统筹 李天麟:界面音乐 徐侃:代码算法 代码初步已经完成.还差最后一步整合.附上最后一张截图

  6. 爬虫时http错误提示

    在爬虫,请求网站的时候,有时候出现域名报错,所出现的代码所对应的意思:

  7. 使用Java+Kotlin双语言的LeetCode刷题之路(二)

    BasedLeetCode LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 ...

  8. 菜鸟教程--AJAX

    一.简介1.AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术.2.AJAX = 异步 JavaScript 和 XML.3.通过在后台与服务器进行少量数据交换,AJAX 可以使网 ...

  9. 【转】CSS颜色代码大全

    转自http://www.cnblogs.com/axing/archive/2011/04/09/CSS.html FFFFFF #DDDDDD #AAAAAA #888888 #666666 #4 ...

  10. 关于python 自带csv库的使用心得 附带操作实例以及excel下乱码的解决

    因为上次帮我们产品处理过一个文件,他想生成能excel处理操作的.但是上次由于时间非常紧张,所以并没有处理好. 正好无聊就来好好研究一下 ,找算法要了几个 csv文件.来好好玩一玩. 全篇使用了pyt ...