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 <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
string input;
getline(cin,input);
int Pnum[input.size()]={};//Pnum数组表示该字符左侧字符P的数量
for(int i=;i<input.size();++i)
{//如果i-1位置是P字符,则Pnum[i]=Pnum[i-1]+1;否则Pnum[i]=Pnum[i-1]
Pnum[i]=Pnum[i-];
if(input[i-]=='P')
++Pnum[i];
}
int tnum=,sumPAT=;//tnum表示该字符右侧字符T的数量,sumPAT表示PAT字符串总数
for(int i=input.size()-;i>=;--i)
if(input[i]=='T')
++tnum;
else if(input[i]=='A')
sumPAT=(sumPAT+Pnum[i]*tnum)%;
printf("%d\n",sumPAT);
return ;
}
 

PAT甲级——A1093 Count PAT's【25】的更多相关文章

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

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

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

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

  3. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  4. A1093 Count PAT's (25 分)

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

  5. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  6. 【PAT甲级】1083 List Grades (25 分)

    题意: 输入一个正整数N(<=101),接着输入N个学生的姓名,id和成绩.接着输入两个正整数X,Y(0<=X,Y<=100),逆序输出成绩在x,y之间的学生的姓名和id. tric ...

  7. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  8. PAT甲级 1125. Chain the Ropes (25)

    1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  9. PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)

    1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...

随机推荐

  1. JS对象 charAt() 方法可返回指定位置的字符。返回的字符是长度为 1 的字符串。

    返回指定位置的字符 charAt() 方法可返回指定位置的字符.返回的字符是长度为 1 的字符串. 语法: stringObject.charAt(index) 参数说明: 注意:1.字符串中第一个字 ...

  2. XSS攻击原理

    本文转载的地址:http://www.2cto.com/Article/201209/156182.html Xss(cross-site scripting)攻击指的是攻击者往Web页面里插入恶意h ...

  3. 家庭-养老院模型理解IOC和DI

    控制反转 IOC 1. 概念 应用内部不负责依赖对象的创建和维护, 由第三方负责, 这样控制权就由应用内部转移到外部容器, 控制权的转移就是所谓的反转. 2. 比喻 有一户家庭(应用)有个老人(依赖对 ...

  4. 树莓派3B+ 人脸识别、摄像头安装和使用

    最近在学校里折腾树莓派上的人脸识别,折腾了很久才能用 在此记录下使用的过程和遇到的困难 过程基于超有趣!手把手教你使用树莓派实现实时人脸检测完成的.其中前面opencv的安装是文章中的Raspbian ...

  5. 用while实现登录操作(3次过后,输入yes,使counter置0,还可以玩)

    用while实现登录操作(输入yes,使counter置0,还可以玩)#_author:Administrator#date:2019/10/24user_name="star"p ...

  6. java在使用equals的时候一种习惯帮忙隔离大部分空指针

    相同的一段代码: 所以,在平时编码的时候,尽量把需要比对的不为空的放在equal前面,比如判断 i 是否等于 1,那么使用 1.equals(i) 更为合适,在equals源码中 传入的是object ...

  7. 17个方法防止dedeCMS织梦网站被黑挂木马

    dede织梦cms系统的程序存在漏洞,黑客攻击方法层出不穷,导致网站经常被黑,被百度安全中心等拦截,影响排名和流量,让站长非常头疼,下面总结一些防止dede织梦cms系统被攻击设置的方法,可有效的防止 ...

  8. Duilib中各个类的简单介绍

    DirectUI意为直接在父窗口上绘图(Paint on parent dc directly).即子窗口不以窗口句柄的形式创建(windowless),只是逻辑上的窗口,绘制在父窗口之上.微软的“D ...

  9. springboot下自定义配置文件,并在项目里读取的方法

    首先 pom文件引入springboot文件处理器 <dependency> <groupId>org.springframework.boot</groupId> ...

  10. iOS开发Drag and Drop简介

    1.Drag and Drop简介 Drag and Drop是iOS11的新特性,可以将文本.图片进行拖拽到不同app中,实现数据的传递.只不过只能在iPad上使用,iPhone上只能app内部拖拽 ...