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 ...
随机推荐
- 第二百五十七节,Tornado框架-路由映射,逻辑处理,文件归类配置
Tornado框架-路由映射,逻辑处理,文件归类配置 Tornado框架 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起 ...
- 视图矩阵的推导-opengl应用
把物体从世界坐标系转化到视点坐标系的矩阵称为视图矩阵. 下面我们先看下opengl视图矩阵的推导过程: 假设视点或camera的局部坐标系为UVN,UVN分别指向右方.上方和后方从而构成右手坐标系,视 ...
- 去掉if
修改前 namespace CleanCSharp.Methods.Dirty { class BooleanSwitchingArgumentsExample { p ...
- ajax 请求登录超时跳转登录页的示例代码
Ajax AJAX即“Asynchronous Javascript + XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. 在Filter里判断是否登录,如果未 ...
- MP 及OMP算法解析
转载自http://blog.csdn.net/pi9nc/article/details/18655239 1,MP算法[盗用2] MP算法是一种贪心算法(greedy),每次迭代选取与当前样本残差 ...
- 剑指 offer set 11 最小的K个数
总结 1. 假如允许修改给定数组, 那么通过快排的子过程, 可以在 o(n) 时间复杂度内得出结果. 2. 对于海量数据和不允许修改的数据, 通过最小堆的方式更好, 通过维持一个大小为 K 的最小堆
- WPF进阶之接口(2):IDisposable,ICollectionView
废话不多说,进入正题,先来说说IDisposable,看例子(来自MSDN): using System; using System.ComponentModel; // 下面的例子将展示一个实施了I ...
- EF简单查询
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- studio导入Eclipse 项目要改的文件
添加下面文件即可,一个不能少 1. project 2.project.properties 3.classpath 4.AndroidManifest.xml 以上目录都有可以正常导入studio中
- 用VS不同版本打开项目,报错:MS Build Error MSB4019: Microsoft.WebApplication.targets was not found
本例是在用VS2008打开项目是报错 未找到C:\Program Files\MSBuild\Microsoft\VisualStudio\V10.0 In the last article Buil ...