本文同步发布在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. Netty,Netty

    Windows防火墙会自动关闭空闲的TCP链接,所以Netty需要心跳,如果发现链接断开需要进行关闭Session: 怎么来理解TCP的流式传输呢? int blocksize = buffer.re ...

  2. QTP使用outlook发送邮件

    '发邮件 Dim objOutlook  Dim objOutlookMsg Dim olMailItem  ' Create the Outlook object and the new mail ...

  3. J2EE 学习路线

    分享一个比较好的学习网站    http://edu.51cto.com/roadmap/view/id-86.html ================================J2EE=== ...

  4. IPC编程之消息队列

    本地的进程间通信(IPC)有很多种方式,但可以总结为下面3类: 1.消息传递(管道.FIFO.消息队列) 2.同步(互斥量.条件变量.读写锁.文件和写记录锁.信号量) 3.共享内存(匿名的和具名的) ...

  5. DBVisualizer Pro for mac

    公司使用的是DB2数据库,支持DB2的数据库客户端常用的有DBeaver和DBVisualizer.DBeaver是免费的,但本人电脑安装后,启动一直报错,问题一直没解决就放弃了.改用DBVisual ...

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

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

  7. R语言对矩阵按某一列排序

    [plain] view plaincopy a <- c(5,4,3,2,1) b <- c(1,2,3,4,5) c <- cbind(a,b) [plain] view pla ...

  8. 31、NGS 常用分析软件

    转载:http://www.zilhua.com/2081.html 参考资料:http://bioinfo.mc.vanderbilt.edu/NGS/software.htm 1. Mapping ...

  9. 【mongodb】json与bson区别

    bson是由10gen开发的一个数据格式,目前主要用于mongoDB中,是mongoDB的数据存储格式.bson基于json格式,选择json进行改造的原因主要是json的通用性及json的schem ...

  10. storm源码分析之topology提交过程

    storm集群上运行的是一个个topology,一个topology是spouts和bolts组成的图.当我们开发完topology程序后将其打成jar包,然后在shell中执行storm jar x ...