pat1093. Count PAT's (25)
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 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 105characters 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<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
#define mod 1000000007
int main(){
string s;
cin>>s;
int countP=,countPA=,count=;
int i;
for(i=;i<s.length();i++){
if(s[i]=='P'){
countP++;
countP=countP%mod;
}else{
if(s[i]=='A'){
countPA+=countP;
countPA=countPA%mod;
}
else{
count+=countPA;
count=count%mod;
}
}
}
cout<<count<<endl;
return ;
}
pat1093. Count PAT's (25)的更多相关文章
- PAT1093: Count PAT's
1093. Count PAT's (25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng The strin ...
- Count PAT's (25) PAT甲级真题
题目分析: 由于本题字符串长度有10^5所以直接暴力是不可取的,猜测最后的算法应该是先预处理一下再走一层循环就能得到答案,所以本题的关键就在于这个预处理的过程,由于本题字符串匹配的内容的固定的PAT, ...
- 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 ...
- 1093. Count PAT’s (25)-统计字符串中PAT出现的个数
如题,统计PAT出现的个数,注意PAT不一定要相邻,看题目给的例子就知道了. num1代表目前为止P出现的个数,num12代表目前为止PA出现的个数,num123代表目前为止PAT出现的个数. 遇到P ...
- 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 ...
- A1093 Count PAT's (25 分)
一.技术总结 这是一个逻辑题,题目大职意思是可以组成多少个PAT,可以以A为中心计算两边的P和T,然后数量乘积最后相加便是答案. 还有一个注意的是每次相加后记得mod,取余,不要等到最后加完再取余,会 ...
- 【PAT甲级】1093 Count PAT's (25 分)
题意: 输入一行由大写字母'P','A','T',组成的字符串,输出一共有多少个三元组"PAT"(相对顺序为PAT即可),答案对1e9+7取模. AAAAAccepted code ...
- PAT甲级 1093 Count PAT‘s (25 分) 状态机解法
题目 原题链接 The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the ...
- PAT (Advanced Level) 1093. Count PAT's (25)
预处理每个位置之前有多少个P,每个位置之后有多少个T. 对于每个A,贡献的答案是这个A之前的P个数*这个A之后T个数. #include<cstdio> #include<cstri ...
随机推荐
- 树莓派(Raspberry Pi 3) centos7 扩容内存卡
在使用Win32DiskImager为一张空白的SD卡刷入新的centos7系统后,发现卡上的可用剩余空间并不大,用df -h查看,根目录下的空间使用率居然是25%,而且总空间也就2G左右.网上查到的 ...
- win10系统遇到的问题解决
1.win10 计算器提示:需要新应用打开此calculator 运行calc,会出现需要新应用打开此Calculator,打开应用商店,找到计算器,仍然可以被使用,我怀疑是我自己在清理PC的注册 ...
- Codeforces 917B MADMAX (DP+博弈)
<题目链接> 题目大意:给定一个DAG图,其中图的边权是给定的字符所对应的ascii码,现在A先手,B后手,每次沿DAG图走一步,但是第i次走的边权一定要大于等于第i-1次走的边权(这里是 ...
- Redis源码阅读---连接建立
对于并发请求很高的生产环境,单个Redis满足不了性能要求,通常都会配置Redis集群来提高服务性能.3.0之后的Redis支持了集群模式. Redis官方提供的集群功能是无中心的,命令请求可以发送到 ...
- server12装.NET 3.5
参考:https://support.microsoft.com/en-us/help/2734782/net-framework-3-5-installation-error-0x800f0906- ...
- findControl 可以获取前台页面的控件
findControl 可以获取前台页面的控件
- FPGA基础学习(1) -- FFT IP核(Quartus)
为了突出重点,仅对I/O数据流为steaming的情况作简要说明,以便快速上手,有关FFT ip核模型及每种设置详细介绍请参考官方手册FFT MegaCore Function User Guide. ...
- C#获取单元格值(使用NPOI插件)
/// <summary> /// 获取单元格的值 /// </summary> /// <param name="item"></par ...
- Codeforces-D-Diverse Garland(思维)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- Python入门字符编码
计算机基础知识 一.应用程序任何操作硬件的请求都需要向操作系统发起系统调用,然后由操作系统去操作硬件 二.文本编辑器存取文件的原理 1.打开编辑器就打开了启动了一个进程,是在内存中的,所以,用编辑器编 ...