本文同步发布在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. 数据交换格式XML和JSON对比

    1.简介: XML:extensible markup language,一种类似于HTML的语言,他没有预先定义的标签,使用DTD(document type definition)文档类型定义来组 ...

  2. ffmpeg avpicture_fill的一些使用

    标签: ffmpegavpicture_fill 2013-05-17 10:03 4713人阅读 评论(1) 收藏 举报  分类: ffmpeg(3)  这个FFMPEG我没找到详细的中文教程,只有 ...

  3. 删除老的Azure Blob Snapshot

    客户有这样的需求:每天需要对VM的数据进行备份,但如果备份的时间超过一定的天数,需要进行清除. 本文也是在前一篇Azure Blob Snapshot上的优化. "Azure blob St ...

  4. HDOJ1238(string)

    Substrings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. 【转】 Pro Android学习笔记(三九):Fragment(4):基础小例子-续

    目录(?)[-] Step 3实现简介显示类DetailFragment 创建实例 编写所需的生命周期代码 Step 4实现showDetailint index如何管理fragment fragme ...

  6. 四 Synchronized

    首先,一个问题:一个boolean成员变量,一个方法赋值,一个方法读值,多线程环境下,需要同步吗? 如果用同步的话,读也要用synchroized修饰,因为可见性的问题 需要同步,或者用volatil ...

  7. VUE之使用百度地图API

    利用vue创建点餐系统,在点餐系统中需要知道商家地址信息,这时就需要借用百度地图API. 步骤一:申请百度地图密钥: 步骤二:在index.html中添加百度地图JavaScript API接口: & ...

  8. hive一些思考

    Hive查询 1.hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供完整的sql查询功能,可以将sql语句转换为MapReduce任务进行运行.其优点是学习 ...

  9. 孙鑫VC学习系列教程

    教程简介 1.循序渐进 从Win32SDK编程开始讲解,帮助大家理解掌握Windows编程的核心 -- 消息循环机制. 2.通俗易懂 编程语言枯燥难懂,然而通过孙鑫老师形象化的讲解,Windows和M ...

  10. 功能:formatter 表单提交 拼接参数的形式

    datagarid的formatter属性 value: 代表当前单元格中的值.row:代表当前行.index: 代表当前行的下标. {field:'is_hot',title:'是否热门',widt ...