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 1 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<cstring>
const int maxn = ;
const int MOD = ;
char str[maxn];
int leftNumP[maxn] = {};
int main(){
fgets(str,maxn,stdin);
int len = strlen(str);
for(int i = ; i < len; i++){
if(i > ){
leftNumP[i] = leftNumP[i-];
}
if(str[i] == 'P'){
leftNumP[i]++;
}
}
int ans = ,rightNumT = ;
for(int i = len - ; i >= ; i--){
if(str[i] == 'T'){
rightNumT++;
}else if(str[i] == 'A'){
ans = (ans + rightNumT * leftNumP[i]) % MOD;
}
}
printf("%d\n",ans);
return ;
}
1093 Count PAT's(25 分)的更多相关文章
- 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甲级】1093 Count PAT's (25 分)
题意: 输入一行由大写字母'P','A','T',组成的字符串,输出一共有多少个三元组"PAT"(相对顺序为PAT即可),答案对1e9+7取模. AAAAAccepted code ...
- 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 ...
- 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 ...
- A1093 Count PAT's (25 分)
一.技术总结 这是一个逻辑题,题目大职意思是可以组成多少个PAT,可以以A为中心计算两边的P和T,然后数量乘积最后相加便是答案. 还有一个注意的是每次相加后记得mod,取余,不要等到最后加完再取余,会 ...
- PAT (Advanced Level) 1093. Count PAT's (25)
预处理每个位置之前有多少个P,每个位置之后有多少个T. 对于每个A,贡献的答案是这个A之前的P个数*这个A之后T个数. #include<cstdio> #include<cstri ...
- PAT甲级——1093 Count PAT's (逻辑类型的题目)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分) ...
- pat1093. Count PAT's (25)
1093. Count PAT's (25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng The strin ...
- PAT 1093 Count PAT's[比较]
1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...
随机推荐
- Poj 1973 Software Company(二分+并行DP)
题意:软件公司接了两个项目,来自同一个合同,要一起交付.该公司有n个程序猿来做这两个项目A和B,每个项目都被分为m个子项目,给定每个程序猿做一个A中的子项目需要的时间Xi秒,和做B中的子项目所需时间Y ...
- Java应用中使用ShutdownHook友好地清理现场、退出JVM的2种方法
Runtime.getRuntime().addShutdownHook(shutdownHook); 这个方法的含义说明: 这个方法的意思就是在jvm中增加一个关闭的钩子,当jv ...
- 人物-IT-马化腾:马化腾
ylbtech-人物-IT-马化腾:马化腾 马化腾,1971年10月29日生于原广东省海南岛东方市八所港(今海南省东方市),祖籍广东省汕头市.腾讯公司主要创办人之一.现任腾讯公司董事会主席兼首席执行官 ...
- Python模块-requests(一)
requests不是python自带的,使用前需要安装 发送请求 HTTP请求类型有GET,POST,PUT,DELETE,HEAD和OPTIONS 使用requests发送请求的方法如下: > ...
- 问题:sqlserver if;结果: SqlServer if else和case
SqlServer if else和case 分类: SQLSERVER 2013-03-01 16:51 11328人阅读 评论(0) 收藏 举报 行转列 目录(?)[+] if else 要提示的 ...
- 使用union来遍历结构体中的成员
前几天和实验室的同学讨论问题的时候发现他使用的一段数据校验的代码自己以前没有接触过,今天有空就把它整理了一下. #include <stdio.h> #include <stdlib ...
- JavaScript中的BOM知识框架
浏览器对象模型(BOM)以window对象为依托,表示浏览器窗口及可见区域.同时,window对象和还是全局对象,因此所有求安局变量和函数都是它的属性,所有原生框架及其他函数都在它命名之下.BOM中对 ...
- List for game to play latter
1.The Elder Scrolls V 2.Border Lands 1,2 3.Mind Killer 4.Dark Soul 2 5.Watch Dog 6.Valkyria Chronicl ...
- JDBC编程之数据准备
--------------------siwuxie095 JDBC 编程之数据准备 启动 MySQL 服务,在管理员模式下的 CMD 窗口中输入 net start mysqldb 「对应的关闭 ...
- 学习过程的记录:实验室电脑上的jdk环境变量
亲爱的,先区分安装路径和软件的存放路径好不好呢? 1.变量名:JAVA_HOME 变量值:D:\Program Files\Java\jdk1.7.0_21 2. 编辑 Path(粘贴到最后) %JA ...