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 ...
随机推荐
- redis安装配置使用
1.redis官方下载地址:https://redis.io/download 也可以github上下载,redis 64位下载地址:https://github.com/ServiceStack/r ...
- Linux 指令查询帮助
man +指令名 例子: man rename
- 关于Qt5(1)-- 两个窗口互相切换的例子
<QT Creator快速入门>这本书有一章介绍model和modeless的概念时,用到了两个窗口互相切换的例子.但是原文对该例子的说明非常模糊不清,现整理如下. 1,要求:登陆界面.主 ...
- SpringCloudBus
不重启微服务的情况下更新配置 配置服务端 tensquare_config配置依赖 <dependency> <groupId>org.springframework.clou ...
- for循环总结
1.冒泡排序的总结:其实这个很简单的理解,就是用数组里面的第0个元素(也就是[]里面的第一个数,按照数组的话是第一个,让他们进行挨个比较),示例: 排序前: 14 62 38 41 53 62 71 ...
- zookeeper 选举白话理解
- error LNK1104: 无法打开文件“C:\Users\Administrator\Desktop\....\\xxxx.exe”
1.错误原因:项目在在打开前已经打开了win32里面的程序,并且运行. 解决方法:关闭直接在win32中运行的程序,再点击调试 2.暂时不知道原因,打开程序还会报无权限创建可执行文件.如下图所示 解 ...
- 1day:了解python
一.’计算机语言有哪些? 1.开发语言: 高级语言:Python,Java,PHP,C#,C++,(面向字节码) 低级语言:C.汇编(面向机器码) 备注:机器码是直接和计算机硬件沟通,字节码是通过解释 ...
- 操作系统-Windows操作系统的线程调度了解这些
Windows操作系统支持内核级线程,调度单位是线程,它采用基于动态优先级的,抢占式调度,并结合时间配额的调整来完成调度 一.几个前提知识点 就绪线程按优先级进入相应的就绪队列 系统总是选择优先级最高 ...
- 第四周——重新clone项目后maven问题
重新clone项目后,一直报错,"类重复..." clean后install也无效果. 原因是idea在重启项目时会更改maven为默认的idea自带的maven配置,要重新设置