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. html 转word

    今日头条发表文章 python-docx — python-docx 0.8.6 documentation http://python-docx.readthedocs.io/en/latest/

  2. jsp ajax 数据库Demo

    转自:http://blog.csdn.net/rushkid02/article/details/7515058 下面介绍JSP前台表单内容通过Ajax异步提交到后台Servlet进行校验(校验方式 ...

  3. 【POJ 1845】 Sumdiv

    [题目链接] 点击打开链接 [算法] 不妨先将A分解质因数 A = p1^q1p2^p2p3^p3..pn^qn 那么,A^B = p1^q1Bp2^q2B...pn^qnB 根据约数和定理,A^B的 ...

  4. ubuntu16.04 Kafka 安装

    Kafka核心概念: 下面介绍Kafka相关概念,以便运行下面实例的同时,更好地理解Kafka. 1. Broker Kafka集群包含一个或多个服务器,这种服务器被称为broker 2. Topic ...

  5. sql 全站搜索

    SQL全站搜索 create proc Full_Search(@string varchar(50)) as begin declare @tbname varchar(50) declare tb ...

  6. Java Itext 生成PDF文件

    利用Java Itext生成PDF文件并导出,实现效果如下: PDFUtil.java package com.jeeplus.modules.order.util; import java.io.O ...

  7. ACM_百度的面试(单调栈)

    百度的面试 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在一个二维平面,从左到右竖立n根高度分别为:a[1],a[2],... ...

  8. Java. How to use headless browsers for crawling web and scraping data from website.--转

    https://www.linkedin.com/pulse/java-how-use-headless-browsers-crawling-web-scraping-data-taluyev/ Di ...

  9. unity多语言本地化

    简介 嗯...一般来说做游戏啥的都不会只发一个国家,但是每个国家语言不同,就存在多语言本地化的问题,然后直接用过一个通过xml完成本地化的东东,然后策划反馈不会修改xml,扔给我一个excel让我自己 ...

  10. InputStream和Reader

    java.io下面有两个抽象类:InputStream和ReaderInputStream是表示字节输入流的所有类的超类Reader是用于读取字符流的抽象类InputStream提供的是字节流的读取, ...