PAT 有几个PAT
字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T);第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T)。
现给定字符串,问一共可以形成多少个 PAT?
输入格式:
输入只有一行,包含一个字符串,长度不超过105,只包含 P、A、T 三种字母。
输出格式:
在一行中输出给定字符串中包含多少个 PAT。由于结果可能比较大,只输出对 1000000007 取余数的结果。
输入样例:
APPAPT
输出样例:
2
a=input()
countt,countp,count=0,0,0
for i in a:
if i=='T':
countt+=1
for j in range(len(a)):
if a[j]=='P':
countp+=1
if a[j]=='T':
countt-=1
if a[j]=='A':
count+=countt*countp%1000000007
print('%d'%(count%1000000007))
每一个A对应的PAT的数量是它之前的P的数量与它之后的T的数量的乘积,然后把每个A对应的数量加和就是所有的PAT的数量。于是,找A之后T的数量就可以用 T的数量-A之前T的数量 来计算。那么就先遍历字符串,把T的数量统计一下,然后再遍历字符串,遇到T,先前统计的T的数量就 -1
PAT 有几个PAT的更多相关文章
- PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
- PAT——有几个PAT
思路来源:https://www.cnblogs.com/asinlzm/p/4440603.html 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6 ...
- PAT甲 1095 解码PAT准考证/1153 Decode Registration Card of PAT(优化技巧)
1095 解码PAT准考证/1153 Decode Registration Card of PAT(25 分) PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级: ...
- PAT甲级——1093 Count PAT's (逻辑类型的题目)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分) ...
- PAT Basic 1095 解码PAT准考证 (25 分)
PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级:B 代表乙级: 第 2~4 位是考场编号,范围从 101 到 999: 第 5~10 位是考试日期,格式为年.月. ...
- PAT甲级——A1093 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 (25 分) 状态机解法
题目 原题链接 The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the ...
- PAT (Advanced Level) 1075. PAT Judge (25)
简单模拟题. 注意一点:如果一个人所有提交的代码都没编译通过,那么这个人不计排名. 如果一个人提交过的代码中有编译不通过的,也有通过的,那么那份编译不通过的记为0分. #include<cstd ...
- PAT (Advanced Level) 1025. PAT Ranking (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- 《C程序设计语言》 练习3-3
问题描述 编写expand(s1,s2),将字符串s1中类似于a-z类的速记符号在字符串s2中扩展为等价的完整列表abc.....xyz.该函数可以处理大小写字母和数字,并可以处理a-b-c,a-z0 ...
- PAT 1011 World Cup Betting (20分) 比较大小难度级别
题目 With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly exc ...
- iptables做nat网络地址转换
iptables做nat网络地址转换. 0. 权威文档 http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO-6.html e文好的直接跳过本文 ...
- Codeforces1157A(A题)Reachable Numbers
A. Reachable Numbers Let's denote a function f(x)f(x) in such a way: we add 11 to xx, then, while th ...
- nginx配置之代理功能
nginx代理功能 至少需要两台主机: 代理机配置----如下: yum安装的/etc/nginx/nginx.conf location / { #服务机的ip端口 proxy_pass http: ...
- JS如何判断是否已经引入某个css或是js?
http://bbs.csdn.net/topics/390541081 function isInclude(name){ var js= /js$/i.test(name); va ...
- Word与Excel中,如何输入✔标志
为了表达值的对错,或者相关任务是否完成,我们需要在word及excel中输入[√]和[x] Word与Excel中如何在方框“口”中打勾[√]和[x],在Word中打钩的方法有3种:第一种,在插入特殊 ...
- block和delegate的选择
block和delegate均为常用回调方式 (暂不讨论通知) 代理 优点: 设置某个对象的代理,代理对象可以与被代理对象不直接相关,即使两个对象距离较远,传值也比较方便. 代理方法内可以方便调用 ...
- poj3621 SPFA判断正环+二分答案
Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big c ...
- 【NLP】老司机带你入门自然语言处理
自然语言处理是一门用于理解人类语言.情感和思想的技术,被称为是人工智能皇冠上的明珠. 随着深度学习发展,自然语言处理技术近年来发展迅速,在技术上表现为BERT.GPT等表现极佳的模型:在应用中表现为c ...