1040 有几个PAT (25 分)
题目:1040 有几个PAT (25 分)
思路:
- 是个规律题,只要找到规律就有思路,那代码基本就有了,就是怎么实现比较好和是否简洁的问题。
- 很明显:A是分水岭,A前面有多少个P和A后面有多少个T知道的话,那有几个PAT就是P的个数*T的个数的问题了。
- 总个数为前面所有A所在位置能构成的PAT数+现在A所在位置能构成的PAT数。
- 详情代码。
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;
const int mod = ; int main()
{
string s;
cin >> s;
int cntt = , cntp = , sum = ;
for(int i = ; i < s.length(); i++)
{
if(s[i] == 'T') //先记录全部的T的个数
cntt++;
}
for(int i = ; i < s.length(); i++)
{
if(s[i] == 'P') //记录A前的P的个数
cntp++;
else if(s[i] == 'T') //A前的T没用,减去
cntt--;
else if(s[i] == 'A') //一旦遇到A,此时的P和T的个数就是满足条件的,进行计算
sum = (sum + cntp * cntt) % mod;
}
printf("%d", sum);
return ;
}
总结:
找规律题,规律是一下就找到了,但是找到方法去实现代码也很重要。
1040 有几个PAT (25 分)的更多相关文章
- PAT Basic 1040 有几个PAT (25 分)
字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T). 现 ...
- 1040 有几个PAT (25 分)C语言
字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位§,第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位§,第 4 位(A),第 6 位(T). 现给定字符 ...
- 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, nam ...
- PAT甲级——1153.Decode Registration Card of PAT(25分)
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- PAT 1040有几个PAT
原题:https://pintia.cn/problem-sets/994805260223102976/problems/994805282389999616 1040 有几个PAT (25 分) ...
- PAT乙级1040 有几个PAT
题目: 1040 有几个PAT (25分) 字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位 ...
- PAT(B) 1040 有几个PAT(Java)
题目链接:1040 有几个PAT (25 point(s)) 题目描述 字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位§,第 4 位(A),第 6 位(T):第二个 ...
- 1040 有几个PAT (25 分)
题目链接:1040 有几个PAT (25 分) 做这道题目,遇到了新的困难.解决之后有了新的收获,甚是欣喜! 刚开始我用三个vector数组存储P A T三个字符出现的位置,然后三层for循环,根据字 ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
随机推荐
- gitee上传下载代码命令
在想要下载的文件夹下,鼠标右键,git bash 1.输入git init 进行初始化 2.git remote add origin https://gitee.com/XXXXXXXXXXXXXX ...
- CMake变量(提供信息的变量)
目录 CMAKE_VERSION CMAKE_MAJOR_VERSION CMAKE_MINOR_VERSION CMAKE_PATCH_VERSION CMAKE_TWEAK_VERSION CMA ...
- 91.一次性处理多条数据的方法:bulk_create,update,delete
(1)bulk_create: 可以一次性的创建多个对象 示例代码如下: from django.http import HttpResponse from .models import Pulish ...
- 记一次Java面试问题点总结
引言 昨日接了一个阿里外包的电话面试,问了一些技术问题感觉到自己是真的菜,接触Java开发已经也有一段时间,技术方面说来惭愧,一直以来只是局限于框架工具的用法,也没有进行了解其实现的原理,更重要的是一 ...
- leetcode中二分查找的具体应用
给定一个按照升序排列的整数数组 nums,和一个目标值 target.找出给定目标值在数组中的开始位置和结束位置. 你的算法时间复杂度必须是 O(log n) 级别. 如果数组中不存在目标值,返回 [ ...
- win10 python 3.7 pip install tensorflow
环境: ide:pyCharm 2018.3.2 pyhton3.7 os:win10 64bit 步骤: 1.确认你的python有没有装pip,有则直接跳2.无则cmd到python安装目录下ea ...
- You are attempting to install the android sdk inside your android studio installation
原因 我的android studio文件名为AndroidStudio 我的android studio sdk文件名为AndroidStudioSDK 所以系统把AndroidStudioSDK自 ...
- java数据库执行迁移报错Error creating bean with name 'flywayInitializer' defined in class path resource
报错原因 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayI ...
- TPO1-2 The Origin of Theater
Stories (myths) may then grow up around a ritual. Frequently the myths include representatives of th ...
- unless|until|LABEL|{}|last|next|redo| || |//|i++|++i
#!/usr/bin/perl use strict; use warnings; $_ = 'oireqo````'; unless($_ =~ /^a/m){print "no matc ...