一、技术总结

  1. 这是一个逻辑题,题目大职意思是可以组成多少个PAT,可以以A为中心计算两边的P和T,然后数量乘积最后相加便是答案。
  2. 还有一个注意的是每次相加后记得mod,取余,不要等到最后加完再取余,会报错可能会溢出。

二、参考代码

#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 100010;
const int inf = 1000000007;
int leftNump[maxn] = {0};
string str;
int main(){
getline(cin, str);
int len = str.length();
for(int i = 0; i < len; i++){
if(i > 0) leftNump[i] = leftNump[i-1];
if(str[i] == 'P'){
leftNump[i]++;
}
}
int ans = 0, rightNumT = 0;
for(int i = len-1; i >= 0; i--){
if(str[i] == 'T') rightNumT++;
else if(str[i] == 'A'){
ans = (ans + leftNump[i] * rightNumT) % inf;
}
}
cout << ans;
return 0;
}

A1093 Count PAT's (25 分)的更多相关文章

  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甲级】1093 Count PAT's (25 分)

    题意: 输入一行由大写字母'P','A','T',组成的字符串,输出一共有多少个三元组"PAT"(相对顺序为PAT即可),答案对1e9+7取模. AAAAAccepted code ...

  3. 1040 有几个PAT (25 分)

    题目链接:1040 有几个PAT (25 分) 做这道题目,遇到了新的困难.解决之后有了新的收获,甚是欣喜! 刚开始我用三个vector数组存储P A T三个字符出现的位置,然后三层for循环,根据字 ...

  4. pat1093. Count PAT's (25)

    1093. Count PAT's (25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng The strin ...

  5. PTA 10-排序5 PAT Judge (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/677 5-15 PAT Judge   (25分) The ranklist of PA ...

  6. PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)

    1075 PAT Judge (25分)   The ranklist of PAT is generated from the status list, which shows the scores ...

  7. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

  8. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  9. 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 ...

随机推荐

  1. 错题shell

    1.判断/root/class21/inittab.txt文件是否大于100行,如果大于,则显示”inittab is a big file.”否者显示”inittab is a small file ...

  2. matlab练习程序(读取列不一致的数据)

    通常情况我们使用matlab载入数据时,使用load或importdata函数基本就能满足需求. 不过如果数据列是不一致的,又不想读数据的时候每一行去遍历,那么可以使用textscan这个函数. 比如 ...

  3. python--numpy生成正态分布数据及randint randn normal的使用

    正太分布:也叫(高斯分布Gaussian distribution),是一种随机概率分布 机器学习中numpy.random如何生成这样的正态分布数据,本篇博客记录这样的用法 import numpy ...

  4. angular ng-bind-html异常Attempting to use an unsafe value in a safe context处理

    在angular中使用ng-data-html渲染dom时,遇到了一个Attempting to use an unsafe value in a safe context错误,官方给出的理由是‘试图 ...

  5. Python巧用法

    #for 与 else 搭配使用(使用break跳过else) a=[1,2,3,4,5] for i in a: print(i) else: print(i, 'I am else!') for ...

  6. 前端之jquery1

    jquery介绍 jQuery是目前使用最广泛的javascript函数库.据统计,全世界排名前100万的网站,有46%使用jQuery,远远超过其他库.微软公司甚至把jQuery作为他们的官方库. ...

  7. 计时 答题 demo

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  8. Promise简单使用,需要在ES6以上

     //Promise延时顺序执行 var waitOne = new Promise(function(resolve, reject) { setTimeout(function(){ resolv ...

  9. v8js-在PHP中运行javascript代码

    起因之前写自动登录操作一个网站的PHP脚本,但是发现该网站用js代码做了cookie的计算和验证,所以使用了v8js. 安装安装v8.(Mac:brew install v8)使用pecl insta ...

  10. 【转载】Gradle for Android 第三篇( 依赖管理 )

    依赖管理是Gradle最闪耀的地方,最好的情景是,你仅仅只需添加一行代码在你的build文件,Gradle会自动从远程仓库为你下载相关的jar包,并且保证你能够正确使用它们.Gradle甚至可以为你做 ...