本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073

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 1 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的组合数量,字符配对要遵循原始字符串的先后顺序。

思路:开三个数组PPos、APos、TPos分别记录'P'、'A'、'T'三个字符所在的位置。遍历APos,对于当前位置的'A',在它之前的'P'的个数和在它之后的'T'的个数之积就是当前的'A'的组合数量,所有的'A'的组合数量之和就是答案。

 #include <iostream>
#include <string>
#include <vector>
using namespace std; vector<int> PPos, APos, TPos;
string s; int main()
{
int num = ;
cin >> s;
for (int i = ; i < s.length(); i++) {
if (s[i] == 'P')
PPos.push_back(i);
if (s[i] == 'A')
APos.push_back(i);
if (s[i] == 'T')
TPos.push_back(i);
}
int PSize = PPos.size(),
ASize = APos.size(),
TSize = TPos.size(),
PIndex = ,
TIndex = ;
for (int i = ; i < ASize; i++) {
while (PIndex < PSize && PPos[PIndex] < APos[i]) {
PIndex++;
}
while (TIndex < TSize && TPos[TIndex] < APos[i]) {
TIndex++;
}
if (TIndex >= TSize)
break;
num += PIndex * (TSize - TIndex);
num = num % ;
}
cout << num << endl;
return ;
}

PAT甲级——1093 Count PAT's (逻辑类型的题目)的更多相关文章

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

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

  2. PAT甲级——A1093 Count PAT's【25】

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

  3. PAT 1093 Count PAT's[比较]

    1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...

  4. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

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

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

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

  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. 1093. Count PAT's

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

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

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

随机推荐

  1. cudnn 卷积例子

    运行环境:linux cuda cudnn cudnn API:https://docs.nvidia.com/deeplearning/sdk/cudnn-developer-guide/index ...

  2. SQL Server 2008可以安装在win7 64位的系统上吗?

    可以安装的.SQL 支持32和64位.安装时它自动选择的.下载时注意是完整安装包. SQLFULL_CHS 2008.iso大小:3.28G 已经过百度安全检测,放心下载  

  3. redisCheckMem脚本

    最近维护的redis cluster需要扫描每个实例的内存使用率,首先我们需要获取实例已经使用的内存,获取实例的最大内存配额,两个值相比就能获取到内存使用比例. 实例的最大内存获取方法: $REDIS ...

  4. Poj 3356 ACGT(LCS 或 带备忘的递归)

    题意:把一个字符串通过增.删.改三种操作变成另外一个字符串,求最少的操作数. 分析: 可以用LCS求出最大公共子序列,再把两个串中更长的那一串中不是公共子序列的部分删除. 分析可知两个字符串的距离肯定 ...

  5. Project Server2016升级安装问题项目中心无法显示

    sharepoint 2016升级后,project server 相关中心页面出现空白页面,这是是sharepoint2016一个bug,解决方案用PWA.resx内容替换PWA.en-us.res ...

  6. Java 数据类型间的相互转化

    Java中常见基本数据类型包括(String除外[引用]) Date(int year,int month,int day,int hour,int minute,int sec); String 格 ...

  7. IPSec方案部署(多业务场景)

    技术点详解—IPSec方案部署 通过前面几期的介绍可以发现IPSec所涉及的参数很多,在具体方案部署过程中有许多灵活选择的地方,本期专栏就专门对IPSec在几种典型环境中的方案部署进行介绍. 一.   ...

  8. ssh的两种连接方法(包括无密码访问)

    一.正常连接方法:ssh root@10.0.0.20 二.无密码连接方法(有两台机器:此处我把被连接的称为服务器,另一台则称为客户端): 1.先在服务器添加目录 .ssh: mkdir  .ssh ...

  9. Springboot ResponseEntity IE无法正常下载文件

    项目在google浏览器下都很nice了,但当测试到IE的时候开始出现各种问题. 项目是前端js通过URL传参fileName到后台解析返回ResponseEntity 前端代码如下: window. ...

  10. 将Linux 标准输出,错误输出重定向到文件

    1.想要把make输出的全部信息,输出到某个文件中,最常见的办法就是: make xxx > build_output.txt 此时默认情况是没有改变2=stderr的输出方式,还是屏幕,所以, ...