本文同步发布在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. linux命令学习笔记(41):ps命令

    Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前 那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程 ...

  2. linux命令学习笔记(37):date命令

    在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用到时间的运算,熟练运用date命令 来表示自己想要表示的时间,肯定可以给自己的工作带来诸多方便. .命令格式: date [参数 ...

  3. 基于Ubuntu交叉编译FFmpeg Windows SDK

    写在前面 FFmpeg是一个开源且跨平台的音视频解决方案,集采集.转码.流式化为一身,项目的libavcodec编解码模块和libavformat媒体格式模块,支持非常非常丰富的编解码格式和容器封装格 ...

  4. ACM学习历程—51NOD1028 大数乘法V2(FFT)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这 ...

  5. 11g RAC 如何备份OCR,利用备份恢复OCR,ocrdump

    OCR备份 OCR的备份有2种方式,自动备份和手工备份. 自动备份策略: Oracle Clusterware 每隔4小时,CRSD 进程会自动对OCR 进行一次备份,在任意时刻,oracle 总会保 ...

  6. nodejs 静态文件服务器

    https://cnodejs.org/topic/4f16442ccae1f4aa27001071 http://blog.csdn.net/zhangxin09/article/details/8 ...

  7. unittest单元测试生成HTML测试报告

    前言: HTMLTestRunner 是 Python 标准库的 unittest 模块的一个扩展,它可以生成 HTML的 测试报告. 一.下载HTMLTestRunnerNew.py文件: 下载链接 ...

  8. wdatePicker时间控件的使用

    wdatePicker时间控件的使用 1.引用wdatePicker控件的js <seript src="../../js/My97DatePicker/wdatePicker.js& ...

  9. HttpApplication 对象的创建过程及HttpModule过滤器的内部实现过程

    最近通过Reflector学习了一下asp.net内部的原理,做做笔记,方便以后查阅. 先看下HttpApplication 对象的创建过程 从IHttpHandler applicationInst ...

  10. CSS3新增的伪类

    Element1 ~ element2:选择前面有element1的所有element2元素 [attr ^= val] 属性值以val开头的元素 [attr $= val] 属性值以val结尾的元素 ...