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 10​5​​ characters containing only PA, 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[比较]的更多相关文章

  1. 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 ...

  2. PAT甲级——1093 Count PAT's (逻辑类型的题目)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分)   ...

  3. 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 ...

  4. 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 ...

  5. 1093. Count PAT's

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  6. 1093. Count PAT’s (25)-统计字符串中PAT出现的个数

    如题,统计PAT出现的个数,注意PAT不一定要相邻,看题目给的例子就知道了. num1代表目前为止P出现的个数,num12代表目前为止PA出现的个数,num123代表目前为止PAT出现的个数. 遇到P ...

  7. 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 ...

  8. 【PAT甲级】1093 Count PAT's (25 分)

    题意: 输入一行由大写字母'P','A','T',组成的字符串,输出一共有多少个三元组"PAT"(相对顺序为PAT即可),答案对1e9+7取模. AAAAAccepted code ...

  9. PAT甲级 1093 Count PAT‘s (25 分) 状态机解法

    题目 原题链接 The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the ...

随机推荐

  1. Requests blocked by CORS policy in spring boot and angular

    在本地启动Spring Boot后端和Angular前端调试时遇到跨域访问的问题导致前端请求失败. 错误描述 Access to XMLHttpRequest at 'http://localhost ...

  2. mybatis 的动态sql语句是基于OGNL表达式的。

    mybatis 的动态sql语句是基于OGNL表达式的.可以方便的在 sql 语句中实现某些逻辑. 总体说来mybatis 动态SQL 语句主要有以下几类:1. if 语句 (简单的条件判断)2. c ...

  3. 工业级别sd卡存贮slc mlc tlc

    slc mlc tlc SLC = Single-Level Cell ,即1bit/cell,速度快寿命长,价格超贵(约MLC 3倍以上的价格),约10万次擦写寿命 MLC = Multi-Leve ...

  4. thinkphp nginx pathinfo模式支持

    最近一个项目中使用了ThinkPHP做为开发框架,URL上我们使用了PATHINFO模式,但是Nginx默认是不支持PATHINFO的,需要进行手动配置才可以,于是我们按照了以下方法进行了Nginx的 ...

  5. Gradle学习系列

    http://www.cnblogs.com/davenkin/p/gradle-learning-1.html

  6. Python+selenium之简单介绍unittest单元测试框架

    Python+selenium之简单介绍unittest单元测试框架 一.unittest简单介绍 unittest支持测试自动化,共享测试用例中的初始化和关闭退出代码,在unittest中最小单元是 ...

  7. iOS开发之--调用打电话,发邮件,发短信的系统功能的代码

    1.调用 自带mail [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hz ...

  8. Qt计算两个时间差

    QTime startTime = QTime::currentTime(); QThread::msleep(SLEEP_TIME_MILL); QTime stopTime = QTime::cu ...

  9. Android无线测试之—UiAutomator UiScrollable API介绍八

    设置滚动方向 一.设置滚动方向相关API 返回值 API 描述 UiScrollable setAsHorizontalList 设置滚动方向为水平滚动 UiScrollable setAsVerti ...

  10. Android 5.0+删除Sdcard文件

    在Android5.0往后的平台上,你想通过单纯的调用File.delete()或着ContentResolver.delete()来删除Sdcard上的文件会删除失败.前者提示没有权限,后者仅仅删除 ...