PAT 1093
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 <bits/stdc++.h>
using namespace std;
#define N 100010
#define P pair<int,int>
#define mod 1000000007
#define ll long long
//APPAPT 有几个不重复的PAT
char s[N];
ll p[N],t[N];
int main()
{
scanf("%s",s);
int l =strlen(s);
if(s[]=='P') p[]=;//因为p[-1]
for(int i =;i<l;i++){
if(s[i]=='P'){
p[i]=p[i-]+;
}
else{
p[i] = p[i-];
}
}
for(int i=l-;i>=;i--){
if(s[i]=='T'){
t[i]=t[i+]+;
}
else{
t[i] = t[i+];
}
}
ll ans = ;
for(int i=;i<l;i++){
if(s[i]=='A'){
ll x=p[i-];
ll y=t[i+];
ans=(ans+x*y%mod)%mod;
}
}
printf("%lld\n",ans);
return ;
}
PAT 1093的更多相关文章
- 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
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 (逻辑类型的题目)
本文同步发布在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 ...
- PAT 乙级1093 字符串A+B (20 分)
1093 字符串A+B (20 分) 给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集.要求先输出 A,再输出 B,但重复的字符必须被剔除. 输入格式: 输入在两行中分别给出 A ...
- 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 ...
随机推荐
- GuGuFishtion HDU - 6390 (欧拉函数,容斥)
GuGuFishtion \[ Time Limit: 1500 ms\quad Memory Limit: 65536 kB \] 题意 给出定义\(Gu(a, b) = \frac{\phi(ab ...
- 未能找到 System.Web.Helpers
This question is a bit old but here's a simple solution - Microsoft seemed to just move this library ...
- cc2530的第二次实验,用按键控制流水灯
按键控制流水灯 具体想要实现按一下按键,然后单片机的三个灯会以流水灯的形式都亮一遍 实验相关寄存器 实验相关电路 宏定义 #define uint unsigned int #define uchar ...
- Eclipse中如何配置lombok
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/qq_41441210/article/d ...
- 洛谷P2577 午餐
题目链接 题意概述:有n个人,第i个人打饭消耗ai时间,离开后吃饭耗费bi时间,将n个人分成两队,合理分配人员使总时间最短并输出总时间. 我们把问题拆分为两个部分.首先是排列顺序,然后是怎么分到两个队 ...
- UE4的联网系统研究
1. 物体复制 具体细节可参考官网内容:http://api.unrealengine.com/CHN/Gameplay/Networking/index.html 这里只挑部分点来展开. 首先,分为 ...
- http 缓存机制简介
我们应该从两个角度来看http的缓存:缓存控制 和 缓存校验.缓存控制:控制缓存的开关,用于标识请求或访问中是否开启了缓存,使用了什么样的存方式.缓存校验:如何校验缓存,缓存的有效期,如何确定缓存是最 ...
- nginx php-fpm 配置问题(2)
问题: Nginx/FPM/PHP all php files say 'File not found.' 解决: 可能情况 1: 在 nginx php-fpm 配置问题(1)文中,我们分析了一种可 ...
- WPF——OXY绘图_old
plotModel = new PlotModel() { Title = "数据统计", LegendTitle = "Max:红色,Min:黄色", Leg ...
- jvm(三)指令重排 & 内存屏障 & 可见性 & volatile & happen before
参考文档: https://tech.meituan.com/java-memory-reordering.html http://0xffffff.org/2017/02/21/40-atomic- ...