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 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<iostream>
using namespace std;
int main(){
string s;
getline(cin,s);
/* 用long long int 防止sum过大,p[]数组中p[i]表示下标为i的A前面有p[i]个P。
sp为目前的P的数量,st表示目前T的数量 */
long long int p[s.size()]={0},sp=0,st=0,sum=0;
/* 先正着遍历一遍用sp记录目前碰到P的数量,一旦遇到A
就把当前P的数量储存到p[i]中,这样每个A前的P的数量就知道了*/
for(int i=0;i<s.size();i++){
if(s[i]=='P')
sp++;
if(s[i]=='A')
p[i]=sp;
}
/* 再倒着遍历一遍,用st记录碰到的 T的数量,当遇到A时
就把p[i](即A前P的数量)乘以st(即该A后的T的数量)加到sum上*/
for(int i=s.size()-1;i>=0;i--){
if(s[i]=='T')
st++;
if(s[i]=='A')
sum+=st*p[i];
}
cout<<sum%1000000007<<endl;
return 0;
}
PAT 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
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 (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 ...
随机推荐
- P4700 算
P4700 算 时间: 1000ms / 空间: 125829120KiB / Java类名: Main 背景 zhx和他的妹子出去玩. 描述
- 【总结】设备树对platform平台设备驱动带来的变化(史上最强分析)【转】
本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74375086 版权声明:本文为博主原创文章,转载请注明http://blog.c ...
- JavaScript检查是否包含某个字符
转自:http://my.oschina.net/u/1450300/blog/389325 indexOf用法: indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置.如 ...
- bzoj 3944 Sum —— 杜教筛
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3944 杜教筛入门题! 看博客:https://www.cnblogs.com/zjp-sha ...
- MySQL 1045登录失败(转)
http://blog.csdn.net/bbirdsky/article/details/8134528# 当你登录MySQL数据库出现:Error 1045错误时(如下图),就表明你输入的用户名或 ...
- 我眼中的SEO——略读一些SEO书后
近些日子一直在看一些SEO方面的书.为人有些浮躁,读SEO实在读不出太大营养,除了第一本书外,之后的书就是在不停地向后翻页.没有过太具体的实践,现在就来写一下我眼中的SEO.还希望各位多多指教. 1. ...
- [App Store Connect帮助]三、管理 App 和版本(4)创建新版本
当您准备分发 App 的新版本时,您创建的新版本使用您为原始版本创建的 App 记录.该新版本将对购买过先前版本的顾客免费可用. 各版本使用的 Apple ID(App 标识符).SKU 和套装 ID ...
- BigInteger、BigDecimal类的使用详解
我们都知道在java里边long算是存储长度比较大的了,但是如果有很大的数我们应该怎么处理呢,不用怕,java还为我们准备了一个BigInteger的类,那么这个类到底能存储多大的数呢,这个一时还真不 ...
- wcf 代理配置
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSett ...
- 在chrome里模拟调试微信浏览器
开发者模式(下面有配图): 开发者模式/DevTools.More tools/Network conditions/User agent/ Custom/安卓或ios代理配置配置 更改User ag ...