1093. Count PAT's
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<cstdio>
#include<iostream>
#include<string.h>
using namespace std;
char str[];
int pnum[] = {, }, tnum[] = {, };
int main(){
long long cntp = , cntt = , ans = ;
scanf("%s", str);
for(int i = ; str[i] != '\0'; i++){
if(str[i] == 'P')
cntp++;
else if(str[i] == 'A')
pnum[i] = cntp;
}
for(int i = strlen(str) - ; i >= ; i--){
if(str[i] == 'T')
cntt++;
else if(str[i] == 'A')
tnum[i] = cntt;
}
for(int i = ; str[i] != '\0'; i++){
if(str[i] == 'A')
ans += tnum[i] * pnum[i];
}
printf("%lld", ans % );
cin >> str;
return ;
}
总结:
1、方法为,统计每个A左边的P个数和右边的T个数,则这个A能组成的PAT即为P个数乘T个数。为避免n^2复杂度,应设置记录数组,在遍历时记录P数和T数。
2、答案要模1000000007。
1093. Count PAT's的更多相关文章
- PAT 1093 Count PAT's[比较]
1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...
- PAT甲级——1093 Count PAT's (逻辑类型的题目)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分) ...
- 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 ...
- 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 ...
- PAT 1093. Count PAT's
The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...
- 【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 ...
随机推荐
- Linux Namespace : PID
PID namespace 用来隔离进程的 PID 空间,使得不同 PID namespace 里的进程 PID 可以重复且互不影响.PID namesapce 对容器类应用特别重要, 可以实现容器内 ...
- 软工个人博客-week7
Part 1 No Silver Bullet - Essence and Accidents of Software Engineering软件工程中没用通用的方法或者技术让软件工程在短 ...
- MSF MS11-050/10-087/Adobe攻击实践及内存保护技术
MSF MS11-050/10-087/Adobe攻击实践及内存保护技术 内存攻击指的是攻击者利用软件安全漏洞,构造恶意输入导致软件在处理输入数据时出现非预期错误,将输入数据写入内存中的某些特定敏感位 ...
- 5-Python3从入门到实战—基础之数据类型(列表-List)
Python从入门到实战系列--目录 列表定义 list:列表(list)是Python内置的一种数据类型,list是一种有序的集合,索引从0开始,可以进行截取.组合等: //创建列表 list1 = ...
- 2017BUAA软工个人作业Week1
大概的功能已经满足 暂时只能用debug中的exe文件 正在改进... https://github.com/qwellk/project1/tree/product1 PSP2.1 Personal ...
- Using svn in CLI with Batch
del %~n0.txt@echo offsetlocal EnableDelayedExpansionfor /f "delims=" %%i in ('DIR /A:D /B' ...
- php多进程pcntl学习-僵尸进程
上个月写的文章,php多进程pcntl学习(一)现在发现并不完整,因为虽然提到了关闭子进程,但是并没有回收子进程,简单的说就是当子进程比父进程先退出,而父进程没对其做任何处理的时候,子进程将会变成僵尸 ...
- [转帖]知乎专栏:正确使用 Docker 搭建 GitLab 只要半分钟
正确使用 Docker 搭建 GitLab 只要半分钟 https://zhuanlan.zhihu.com/p/49499229 很多程序员在内网搭建 gitlab 都搭建的坑坑洼洼,不支持 htt ...
- 小程序的wx.onAccelerometerChange
https://www.2cto.com/kf/201802/724174.html(copy) 也许有人会问,小程序中都是竖直app形态,要横竖屏判断有什么用?即使判断出了横屏状态,你能把小程序横过 ...
- java面向对象的核心思想
java面向对象的特征之一:封装 1.封装性的使用 package edu.tongji.classdemo; /* 封装性 1.封装的目的:保护某些属性和方法不被外部所见 2.封装的实现 为属性和方 ...