PAT甲级——1093 Count PAT's (逻辑类型的题目)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073
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 P
, A
, 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 (逻辑类型的题目)的更多相关文章
- PAT甲级 1093 Count PAT‘s (25 分) 状态机解法
题目 原题链接 The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the ...
- 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 ...
- PAT 1093 Count PAT's[比较]
1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...
- PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
- 【PAT甲级】1093 Count PAT's (25 分)
题意: 输入一行由大写字母'P','A','T',组成的字符串,输出一共有多少个三元组"PAT"(相对顺序为PAT即可),答案对1e9+7取模. AAAAAccepted code ...
- 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 ...
- 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 ...
- 1093. Count PAT's
The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...
- 1093. Count PAT’s (25)-统计字符串中PAT出现的个数
如题,统计PAT出现的个数,注意PAT不一定要相邻,看题目给的例子就知道了. num1代表目前为止P出现的个数,num12代表目前为止PA出现的个数,num123代表目前为止PAT出现的个数. 遇到P ...
随机推荐
- HihoCoder1663双阶乘的末尾数字([Offer收割]编程练习赛40)(暴力||数学)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定正整数x和k,判断是否存在正整数1 ≤ y ≤ x使得x与y同奇偶且(x!!)/(y!!)的个位数字为k. 其中x!! ...
- ACM学习历程—HDU5521 Meeting(图论)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...
- 【LeetCode】081. Search in Rotated Sorted Array II
题目: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would t ...
- PLSQL Developer安装、配置、连接oracle数据库
0.资源准备 1) PLSQL Developer安装包(由于安装包超过10M,无法上传,请自行下载) 2) instantclient_11_2安装包(由于安装包超过10M,无法上传,请自行下载) ...
- 反编译工具Reflector下载(集成FileGenerator和FileDisassembler)
Reflector是一款比较强大的反编译工具,相信很多朋友都用过它,但reflector本身有很多局限性, 比如只能一个一个的查看方法等,但幸好reflector支持插件功能目前网上有很多reflec ...
- mysql--事务demo1----
package com.etc.entity; import java.sql.Connection; import java.sql.PreparedStatement; import java.s ...
- SpringMvc之参数绑定注解详解之一
引言: 前段时间项目中用到了REST风格来开发程序,但是当用POST.PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加 任何注解),查看了提交方式为application/ ...
- Android源码中添加APP
参考罗升阳<Android系统源代码情景分析> 在Android源码中,我们通常把实验性质的Android APP放在packages/experimental目录下.对于一个简单的应用程 ...
- 0008_Python变量
1.变量名:数字,字母,下划线组成,不能以数字开头,不能是Python内部关键字. 2.变量类型:数字,字符串,布尔值(首字母大写) 3.内存与变量: 4. = 赋值 == 比较 is == ...
- 关于android 数据库查询出现 _id column do not exist 的处理
查询的字段必须带上_id字段,否则就会出现此类异常,导致程序崩溃