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 ...
随机推荐
- Python循环加强版——列表生成式
记得我们在其他语言中都学到过循环,尤其是对for循环是再熟悉不过了 比如我有一个数组 a[10]={1,2,3,4,5,6,7,8,9,10} 下面需要依次循环打印出来,C语言首先想到的是 for( ...
- 《图解HTTP》阅读笔记--第七章---确保WEB安全的HTTPS
第七章.确保WEB安全的HTTPSHTTP的缺点:通信使用明文(不加密),内容可能会被窃听 解决---加密处理: //将通信加密 :通过SSL(安全套接层)---HTTPS(超文本传输安全协议)--- ...
- P1742 最小圆覆盖
\(\color{#0066ff}{题目描述}\) 给出N个点,让你画一个最小的包含所有点的圆. \(\color{#0066ff}{输入格式}\) 先给出点的个数N,2<=N<=1000 ...
- 如何实现 MySQL 的读写分离?MySQL 主从复制原理的是啥?如何解决 MySQL 主从同步的延时问题?
如何实现 MySQL 的读写分离? 其实很简单,就是基于主从复制架构,简单来说,就搞一个主库,挂多个从库,然后我们就单单只是写主库,然后主库会自动把数据给同步到从库上去. MySQL 主从复制原理的是 ...
- 微信小程序传数组(Json字符串)到Java后端
一:小程序端: wxml中代码: <!--index.wxml--> <view> <view> <button bindtap="onShow&q ...
- Apache 在 htaccess 禁止访问 和 conf 中的 禁止访问 区别
相信熟悉Web Server的人一定熟悉Apahce.相信熟悉Apahce的人一定知道URL Rewrite.Apache的mod_rewrite模块,可以帮助人们构造出各种各样美化后的URL.在Ap ...
- 【笔记】Django的ORM之删和改
[笔记]Django的ORM之删和改 Django ORM 数据库 一 删除操作 1.视图层 <table border="1"> <thead> < ...
- sp_executesq用法
第一种用法: --@sqlstring :就是你要执行的sql语句字符串--@ParmDefinition: @sqlstring里边用到的参数在这里声明 输出的参数要加output --sp_exe ...
- uva 442
#include<iostream>#include<stack>#include<map>using namespace std;struct node{ int ...
- nc工具详解
nc 安装 yum install -y nc参数: Command Summary: - Use IPv4 - Use IPv6 -D Enable the debug socket opti ...