PAT 1093 Count PAT's[比较]
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 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
题目大意:给出一个字符串,判断其中有多少个PAT串,P A T之间可以有其他字符隔开。
//只要计算每个出现的A之前出现的P的总数,和A之后出现的T的总数,两者相乘,对所有的A的结果相加即可。
#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stdio.h>
#include <queue>
#include<cmath>
#include <vector>
using namespace std; int cntP[];
int main()
{
string s;
cin>>s;
int ct=;//首先在字符串里找出所有A的位置。
vector<int> posA;
posA.push_back();
int pos=;
while(s.find("A",pos)!=string::npos){
pos=s.find("A",pos);
posA.push_back(pos);
pos++;
}
//vector<int> cntP(posA.size());
int index=;//开始计算P的数量
for(int i=;i<s.size();i++){
if(i<posA[index]){
if(s[i]=='P'){
cntP[index-]++;
}
}
if(i==posA[index]){
cntP[index]+=cntP[index-];
}
}
for(int i=;i<posA.size();i++)
cout<<cntP[i]; return ;
}
//我写成了这个样子,但是感觉还是不行的。写不下去了。
下面是柳神的解答,真的太厉害了!!!
//真是恍然大悟的感觉。学习了!
PAT 1093 Count PAT's[比较]的更多相关文章
- 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 ...
- 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 ...
随机推荐
- c/c++学习之c++ 中的list <>容器
http://blog.csdn.net/mazidao2008/article/details/4802617 push 实例化 即添加 http://www.cnblogs.com/BeyondA ...
- (转自)视频流中的DTS/PTS到底是什么;
翻译了一下: Q:hi,这可能是一个弱智问题,但是当我使用bbMEG1.24beta17编码时,一直以来总是遇到这个下溢的问题.我从日志文件中得到的唯一启示就是我应该更改mux率...但是帮助文档却 ...
- 判断站点访问的终端类型(移动端还是pc端)的方法(转)
要了解某个网站是在移动设备上打开的还是在pc web浏览器中打开的,我们可以有以下综合的几种方式来搞定: 通过判断Request.UserAgent中的具体信息来分析判断,因为UserAgent包含了 ...
- 【BZOJ】2555: SubString(后缀自动机)
http://www.lydsy.com/JudgeOnline/problem.php?id=2555 学到了如何快速维护right值orz (不过这仍然是暴力维护,可以卡到O(n) 首先我们在加一 ...
- 【cf489】D. Unbearable Controversy of Being(暴力)
http://codeforces.com/contest/489/problem/D 很显然,我们只需要找对于每个点能到达的深度为3的点的路径的数量,那么对于一个深度为3的点,如果有a种方式到达,那 ...
- zoj 3362(最大费用)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3904 思路:费用流的题,增加一个超级源点和一个超级汇点,然后就是连边 ...
- 转:解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误
操作SQL数据库,Python使用的是版本2.7,但是在运行的时候出现了异常错误UnicodeEncodeError:'ascii' codec can't encode characters in ...
- JavaScript 一、 ES6 声明变量,作用域理解
// JavaScript/* * ========================================================= * * 编译原理 * 尽管通常将 JavaScr ...
- 【翻译】Webpack 4 从0配置到生产模式
查看原文 webpack 4 发布了! webpack 4 作为一个零配置的模块打包器 webpack 是强大的并且有许多独一无二的特点但是有一个痛点就是配置文件. 在中型到大型项目中为webpack ...
- Angular2 组件与模板 -- 输入和输出属性
Input and Output properties 输入属性是一个带有@Input 装饰器的可设置属性,当它通过属性绑定的形式被绑定时,值会"流入"到这个属性. 输出属性是一个 ...