1040 有几个PAT(25 分)

字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T);第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T)。

现给定字符串,问一共可以形成多少个 PAT

输入格式:

输入只有一行,包含一个字符串,长度不超过10?5??,只包含 PAT 三种字母。

输出格式:

在一行中输出给定字符串中包含多少个 PAT。由于结果可能比较大,只输出对 1000000007 取余数的结果。

输入样例:

APPAPT

输出样例:

2

#include<iostream>
using namespace std;
int main(){
  string a;
  getline(cin,a);//得到要判断的字符串
  long p=0,pa=0,pat=0;//三个数分别是保存p,pa,pat数量的,一定要用long不然会因为数太大数据溢出而出错
  for(long i=0;i<a.length();i++){
    if(a[i]==‘P‘)p++;
    else if(a[i]==‘A‘)pa+=p;
    else if(a[i]==‘T‘)pat+=pa;
  }
  cout<<pat%1000000007;
}

原文地址:https://www.cnblogs.com/fromzore/p/9594276.html

时间: 2024-10-10 11:13:48

1040 有几个PAT(25 分)的相关文章

PTA乙级 (*1040 有几个PAT (25分))

1040 有几个PAT (25分) https://pintia.cn/problem-sets/994805260223102976/problems/994805282389999616 #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <cstring> typedef lo

1040 有几个PAT (25分)

25分题中不是很难的一道,没错我就是挑软柿子捏,今天一定要把basic搞完,阿弥陀佛别拖拉了... 第一次提交后三个测试点运行超时(循环过多吧)....一开始是每遇到一个A就从前往后循环看这个A前面有多少P,有多少T. 第二次提交后后两个测试点答案错误,但是不超时了!微笑 - 由于结果可能比较大,只输出对 1000000007取余数的结果.(题目中的说明) 不要忽略这一句,这说明了个数有可能很大,所以将sum改为longlong型后面两个测试点就过了!! 呵呵.... 算法思想就是记录每一个A前

PAT Advanced 1153 Decode Registration Card of PAT (25 分)

A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, namely, T for the top level, A for advance and B for basic; the 2nd - 4th digits are the test site number, ranged from 101 to 999; the 5th - 10th digits

浙大pat1040 Longest Symmetric String(25 分)

1040 Longest Symmetric String(25 分) Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you must output 11. Inp

PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you must output 11. In

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 PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT. Input Spe

1025 PAT Ranking (25 分)

1025 PAT Ranking (25 分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately

PAT Advanced 1093 Count PAT&#39;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 numb

PTA乙级 (*1095 解码PAT准考证 (25分))

1095 解码PAT准考证 (25分) https://pintia.cn/problem-sets/994805260223102976/problems/1071786104348536832 题目大意:给出一组学生的准考证号和成绩,准考证号包含了等级(乙甲顶),考场号,日期,和个人编号信息,并有三种查询方式查询一:给出考试等级,找出该等级的考生,按照成绩降序,准考证升序排序查询二:给出考场号,统计该考场的考生数量和总得分查询三:给出考试日期,查询改日期下所有考场的考试人数,按照人数降序,考

1025 PAT Ranking (25分)

1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; struct stu{ int location_number; char