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 ...
随机推荐
- thinkphp 如何调用百度echarts 数据报表插件
echarts官网网址:http://echarts.baidu.com/ echarts源码地址:http://echarts.baidu.com/build/echarts-2.2.7.zip ...
- sublime text 3中配置golang开发环境
1:首先下载 Go源码 https://golang.org/dl/ [根据不同的环境选择] 2:新建文件项目文件夹 存放 D:/Go_project 分别建立 bin src pkg 子 ...
- 解决Maven项目 Missing artifact jdk.tools:jdk.tools:1.7的错误
因学习项目需要,在pom.xml添加hbase-client依赖的时候提示解决Maven工程中报 Missing artifact jdk.tools:jdk.tools:1.7的提示信息,之前遇到这 ...
- mac环境搭建selenium
前言 搭建python+selenium,mac自带python2.7,需要公司使用的python是3.x,可以自己百度安装python环境. 1. selenium安装 1. selenium的安装 ...
- imx6 uboot splash image
跟踪uboot代码,了解imx6 splash image的生成过程. 涉及文件: ./cpu/arm_cortexa8/start.S ./board/freescale/mx6q_sabresd/ ...
- Android 绘制圆环
使用画圆弧的方式绘制圆环和进度条,使用sweepGradient进行渐变. 参考链接 http://blog.csdn.net/u011494050/article/details/39251239 ...
- 360 奇酷行车记录仪12967p 安霸a7
http://www.qikoo.com/che?utm_source=xingchejiluyi_360daohang_xialareci_0528&utm_medium=inside ht ...
- git把任意代码提交到已存在的github库中
git init git add . git remote add origin 远程urlgit branch --set-upstream-to=origin/mastergit pull --a ...
- git chekout分支遇到问题:need merge
解决步骤: 在master上, 1.git add . 2.git commit 3.新建分支,并且checkout到此分支,重新提交
- 说说JSON和JSONP 也许你会豁然开朗
说到AJAX就会不可避免的面临两个问题,第一个是AJAX以何种格式来交换数据?第二个是跨域的需求如何解决 前言 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只 ...