PAT.A1093. Count PAT's

原创 2018年04月17日 01:19:40

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 105 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 <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <iostream>
using namespace std;
int leftp[100010];
char a2[100010];
const int MOD = 1000000007;
int main(){
	scanf("%s", a2);
	int rightt = 0,sum=0;
	int l = strlen(a2);
	for (int i = 0; i < l; i++) {
		if (i > 0) leftp[i] = leftp[i - 1];
		if (a2[i] == 'P') leftp[i]++;
	 }
	for (int i = l - 1; i >= 0; i--) {
		if (a2[i] == 'T') rightt++;
		if (a2[i] == 'A')
			sum = (sum + leftp[i] * rightt) % MOD;
	}
	printf("%d", sum);
	return 0;
	
}

1093. Count PAT's (25)

http://www.patest.cn/contests/pat-a-practise/1093 The string APPAPT contains two PAT's as s...
  • a_big_pig
  • a_big_pig
  • 2015-03-14 19:21:22
  • 1191

【PAT】1093. Count PAT's (25)

The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and...
  • realxuejin
  • realxuejin
  • 2015-10-22 20:09:14
  • 359

1093. Count PAT's (统计PAT的个数)

The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and...
  • h1021456873
  • h1021456873
  • 2016-12-07 19:37:19
  • 203

Pat(A) 1093. Count PAT's (25)

原题目: The string APPAPT contains two PAT’s as substrings. The first one is formed by the 2nd, the 4...
  • huqiao1206
  • huqiao1206
  • 2017-09-04 23:27:37
  • 158

1093. Count PAT's (25)【计数】——PAT (Advanced Level) Practise

题目信息1093. Count PAT’s (25)时间限制120 ms 内存限制65536 kB 代码长度限制16000 B The string APPAPT contains two PA...
  • xianyun2009
  • xianyun2009
  • 2016-05-14 20:26:01
  • 3245

1093. Count PAT's (25)想法题吧,算是排列组合吧

1093. Count PAT's (25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng...
  • u013167299
  • u013167299
  • 2015-03-14 18:34:55
  • 572

【PAT】1093. Count PAT's

关键:转化思路,转为求左边p和右边t的个数 #define LOCAL #include #include #include #include #include using namespa...
  • KID_LWC
  • KID_LWC
  • 2017-01-29 22:45:08
  • 127

PAT 1093. Count PAT's

The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and...
  • solin205
  • solin205
  • 2015-03-19 13:22:53
  • 325

pat1093 Count PAT's

The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and...
  • suichen1
  • suichen1
  • 2015-10-19 17:11:44
  • 179

1093 count PAT's

The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and...
  • Win_Man
  • Win_Man
  • 2015-11-06 21:04:16
  • 199
收藏助手
不良信息举报
您举报文章:PAT.A1093. Count PAT's
举报原因:
原因补充:

(最多只允许输入30个字)