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 long long ll;
using namespace std;
int main()
{
	ll sum=0,cou_p=0,cou_t=0;
	string str;
	cin>>str;
	for(int i=0;i<str.length();i++)
	   if(str[i]==‘T‘) cou_t++;
	for(int i=0;i<str.length();i++)
	{
	   if(str[i]==‘P‘) cou_p++;
	   else if(str[i]==‘T‘) cou_t--;
	   else if(str[i]==‘A‘)
	   	sum+=(cou_p*cou_t);
	}
	printf("%d\n",sum%1000000007);
	return 0;
}

原文地址:https://www.cnblogs.com/jianqiao123/p/12234175.html

时间: 2024-08-05 13:34:13

PTA乙级 (*1040 有几个PAT (25分))的相关文章

1040 有几个PAT (25分)

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

PTA 09-排序2 Insert or Merge (25分)

题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/675 5-13 Insert or Merge   (25分) According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort rem

PAT 乙级 1040.有几个PAT C++/Java

题目来源 字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T). 现给定字符串,问一共可以形成多少个 PAT? 输入格式: 输入只有一行,包含一个字符串,长度不超过1,只包含 P.A.T 三种字母. 输出格式: 在一行中输出给定字符串中包含多少个 PAT.由于结果可能比较大,只输出对 1000000007 取余数的结果. 输入样例: APPAPT 输出样例

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

PTA 06-图2 Saving James Bond - Easy Version (25分)

This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodile

PTA 乙级 1017 A除以B (20 分) C/C++

1017 A除以B (20 分) 本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数.你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立. 输入格式: 输入在一行中依次给出 A 和 B,中间以 1 空格分隔. 输出格式: 在一行中依次输出 Q 和 R,中间以 1 空格分隔. 输入样例: 123456789050987654321 7 输出样例: 17636684150141093474 3 1 #include<stdio.h> 2 #include&

PTA乙级(1077 互评成绩计算 (20分),(C++取整)

C++取整 头文件:#include <cmath> 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 int main() 5 { 6 double a=2.5; 7 cout<<ceil(a)<<endl; //向上取整 8 cout<<floor(a)<<endl; //向下取整 9 cout<<round(a)<<

PTA乙级 (1069 微博转发抽奖 (20分)(vector,map))

1069 微博转发抽奖 (20分) https://pintia.cn/problem-sets/994805260223102976/problems/994805265159798784 1.使用vector来保存输入的用户名. 2.使用map来进行筛选,记录用户是否已经中奖. 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cmath> 5 #in

PTA 5-12 How Long Does It Take (25分)

这题看不太懂题目啊~  参考的http://blog.csdn.net/qq_26437925/article/details/49420089?locationNum=6&fps=1 先放着吧. #include "iostream" #include "vector" using namespace std; int in_degree[101]; /* 记录图的各个节点的入度 */ struct Node { int e; int cost; }; v