PAT 1093 Count PAT's[比较]
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 105 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串,P A T之间可以有其他字符隔开。
//只要计算每个出现的A之前出现的P的总数,和A之后出现的T的总数,两者相乘,对所有的A的结果相加即可。
#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stdio.h>
#include <queue>
#include<cmath>
#include <vector>
using namespace std; int cntP[];
int main()
{
string s;
cin>>s;
int ct=;//首先在字符串里找出所有A的位置。
vector<int> posA;
posA.push_back();
int pos=;
while(s.find("A",pos)!=string::npos){
pos=s.find("A",pos);
posA.push_back(pos);
pos++;
}
//vector<int> cntP(posA.size());
int index=;//开始计算P的数量
for(int i=;i<s.size();i++){
if(i<posA[index]){
if(s[i]=='P'){
cntP[index-]++;
}
}
if(i==posA[index]){
cntP[index]+=cntP[index-];
}
}
for(int i=;i<posA.size();i++)
cout<<cntP[i]; return ;
}
//我写成了这个样子,但是感觉还是不行的。写不下去了。
下面是柳神的解答,真的太厉害了!!!
//真是恍然大悟的感觉。学习了!
PAT 1093 Count PAT's[比较]的更多相关文章
- PAT 1093. Count PAT's
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 (逻辑类型的题目)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分) ...
- 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 ...
- 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 ...
- 【PAT甲级】1093 Count PAT's (25 分)
题意: 输入一行由大写字母'P','A','T',组成的字符串,输出一共有多少个三元组"PAT"(相对顺序为PAT即可),答案对1e9+7取模. AAAAAccepted code ...
- PAT甲级 1093 Count PAT‘s (25 分) 状态机解法
题目 原题链接 The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the ...
随机推荐
- 如果可能的话,使用 PC-Lint、LogiScope 等工具进行代码审查
如果可能的话,使用 PC-Lint.LogiScope 等工具进行代码审查. #include <iostream> #include <algorithm> #include ...
- 【BZOJ】1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛(lis)
http://www.lydsy.com/JudgeOnline/problem.php?id=1669 水题太严重 #include <cstdio> #include <cstr ...
- Windows下基于eclipse的Spark应用开发环境搭建
原创文章,转载请注明: 转载自www.cnblogs.com/tovin/p/3822985.html 一.软件下载 maven下载安装 :http://10.100.209.243/share/so ...
- freemarker include 和 import
lib/my_test.ftl 模板内容如下: <#macto copyright date> <p>Copyright (C)${date}Julia Smith.All r ...
- 给Jquery easyui 的datagrid 每行添加操作链接
背景 我们都知道Jquery的Easy-UI的datagrid能够加入而且自己定义Toolbar,这样我们选择一行然后选择toolbar的对应button就能够对这行的数据进行操作.但实际项目里我们可 ...
- 使用HTML5 WebStorage API构建与.NET对应的会话机制
HTML5的Web Storage API,我们也称为DOMStarage API,用于在Web请求之间持久化数据.在Web Starage API 出现之前,我们都是将客户端和服务端之间的交互数据存 ...
- Ubuntu16.04最快捷搭建小型局域网Git服务器
导读 使用linux操作系统,不得不提Git版本管理器,这个Linus花了两周时间开发的分布式版本管理器(这就是大神,先膜了个拜...),毫无疑问,Git版本管理器与linux系统有着与生俱来的同一血 ...
- 从远程(包括ftp,http等协议)地址获取文件流信息
URL url = new URL("ftp://172.18.251.155:8010/recordsImg/2019-01-28/000008_1548649813267.jpg&quo ...
- TClientDataSet数据源设置
TClientDataSet数据源设置 TClientDataSet数据源设置
- div img span 垂直居中问题
div设置height,line-height影响块元素内的文本垂直居中,块下的a,img,span等行内元素是没能垂直居中,用了vertical-align:middle;可以处理div等块级元素下 ...