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 ...
随机推荐
- 协程 和 async await
协程, 是 为了 避免 闭包传递变量 的 性能损耗 而产生 . 如果不是 为了 避免 闭包传递变量 的 性能损耗 , 线程池 和 Task 已经够了, 不需要 再设计 出 协程 来 . 闭 ...
- vue cli4.0 配置环境变量
温馨提示:本文只适用于vue-cli 3.0 及以上的版本哦~ ------------------正文开始------------------ 开发项目时,经常会需要在不同环境中切换.那么我们如何配 ...
- python - 全局中间件(2.7)
一.场景 在网站的所有页面中可能某些地方都需要相同的数据,此时可以在Django中定义全局数据并存储在session中,或使用模板语言放入页面中 注意:一定要加上 try: 进行潜在的异常捕捉,因为一 ...
- OpenCV实现"你的名字"滤镜
这是一个比较有意思的demo,用到了播送融合,具体效果见下图: 文件结构如图所示 主程序代码 #include"stdafx.h" #include<opencv2/phot ...
- 015_matlab运行C语言
视频教程:https://v.qq.com/x/page/q3039wsuged.html 资料下载:https://download.csdn.net/download/xiaoguoge11/12 ...
- 线程太多导致socket连接池爆满,进程启动不了
Issue: 某部机上跟其它机器的连接有问题,ping可以通,telnet端口不通,可以其它机器可以连接到该机器上的进程. java应用启动不起来,产生以下错误. java.net.SocketExc ...
- 全部文章> Maven
Maven 原 Maven中<resources>标签详解 &nbsp;&nbsp;&nbsp;&nbsp;& ...
- 浅谈LCA
目录 什么是LCA 倍增求LCA dfs bfs 树剖求LCA 什么是LCA LCA就是最近公共祖先 对于有根树\(Tree\)的两个结点\(u.v\),最近公共祖先\(LCA(T,u,v)\)表示一 ...
- About me recently
About me recently Recently I fell that memory has always been problematic.Maybe I hava bee too tired ...
- 简单与实用:SpringMVC的常见使用
一.前言 现在的项目大多数都是使用SpringMVC作为MVC框架.SpringMVC的学习成本较低,容易上手,简单实用. 二.应用 1.@Controller & @RequestMappi ...