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 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
string input;
getline(cin,input);
int Pnum[input.size()]={};//Pnum数组表示该字符左侧字符P的数量
for(int i=;i<input.size();++i)
{//如果i-1位置是P字符,则Pnum[i]=Pnum[i-1]+1;否则Pnum[i]=Pnum[i-1]
Pnum[i]=Pnum[i-];
if(input[i-]=='P')
++Pnum[i];
}
int tnum=,sumPAT=;//tnum表示该字符右侧字符T的数量,sumPAT表示PAT字符串总数
for(int i=input.size()-;i>=;--i)
if(input[i]=='T')
++tnum;
else if(input[i]=='A')
sumPAT=(sumPAT+Pnum[i]*tnum)%;
printf("%d\n",sumPAT);
return ;
}
PAT甲级——A1093 Count PAT's【25】的更多相关文章
- PAT甲级——1093 Count PAT's (逻辑类型的题目)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分) ...
- 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甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
- A1093 Count PAT's (25 分)
一.技术总结 这是一个逻辑题,题目大职意思是可以组成多少个PAT,可以以A为中心计算两边的P和T,然后数量乘积最后相加便是答案. 还有一个注意的是每次相加后记得mod,取余,不要等到最后加完再取余,会 ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- 【PAT甲级】1083 List Grades (25 分)
题意: 输入一个正整数N(<=101),接着输入N个学生的姓名,id和成绩.接着输入两个正整数X,Y(0<=X,Y<=100),逆序输出成绩在x,y之间的学生的姓名和id. tric ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- PAT甲级 1125. Chain the Ropes (25)
1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)
1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...
随机推荐
- linux 下安装maven私服
1.下载最新nexus安装包 下载地址:https://www.sonatype.com/download-oss-sonatype 2.下载JDK7,nexus2版本支持JDK7:nexus1版本支 ...
- PHPSTORM 2016.2 注册
1.由于 http://idea.qinxi1992.cn/ OR http://us.idea.lanyus.com/ 都已经被禁掉了,所以就不能再用License server 去注册了. 如图所 ...
- nginx 知识
nginx如何实现高并发? 启动nginx服务器后,输入 ps -ef |grep nginx,会发现nginx有一个master进程 和若干个worker进程, 这些worker进程是平等的,都是被 ...
- 微信公众号支付出现:“当前页面的URL未注册”
微信公众号H5调起支付时,点击支付按钮出现“当前页面的URL未注册”的提示.解决办法:由于2017年8月1日微信官方把关于支付的信息转移到了商户平台:公众平台微信支付公众号支付授权目录.扫码支付回调U ...
- thinkphp switch标签
用法: <switch name="变量" > <case value="值1" break="0或1">输出内容1 ...
- LUOGU P3919 【模板】可持久化数组(主席树)
传送门 解题思路 给每一时刻建一棵线段树维护当前时刻的值,然后修改的时候直接修改,查询的时候直接查,记住查询完后一定要复制. 代码 #include<iostream> #include& ...
- 有道云笔记新功能发现——有道云笔记剪报,完美解决不开会员保存csdn博客到本地的问题。
怎么用 方法一:谷歌插件 方法二:http://note.youdao.com/web-clipper-chrome.html 添加到书签 功能: 能够把网页浏览的内容保存到有道云笔记 解决了自己的难 ...
- 14.data.js
dict_data = { "_id":1, name:"王五", age:55, gender:true } db.stu.insert(dict_data) ...
- eclipse-帮助文档
Eclipse开发环境配置 1. java环境 安装 本系统使用java6开发,老师使用1.6.0 _45版本开发,如下图所示: “开发工具”目录提供了1.6.0 _45版本32位和6 ...
- h5 上下左右前后居中
.outer { width: 200px; height: 200px; background: red; position: relative; } .inner { position: abso ...