PAT (Advanced Level) Practise 1093 Count PAT's (25)
2016-03-25 19:16
435 查看
1093. Count PAT's (25)
时间限制120 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CAO, Peng
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
统计总共有多少pat,直接算出每个A左边的P数量和右边的T数量相乘即可。
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int L[maxn], R[maxn];
int ans;
char s[maxn];
int main()
{
scanf("%s", s + 1);
for (int i = 1; s[i]; i++)
{
L[i] = L[i - 1] + (s[i] == 'P');
}
for (int i = strlen(s + 1); i; i--)
{
R[i] = R[i + 1] + (s[i] == 'T');
}
for (int i = 1; s[i]; i++)
{
if (s[i] == 'A') (ans += (LL)L[i - 1] * R[i + 1] % mod) %= mod;
}
printf("%d\n", ans);
return 0;
}
相关文章推荐
- libdvbpsi源码分析(四)PAT表解析/重建
- PAT配置
- 什么是端口复用动态地址转换(PAT) 介绍配置实例
- MikroTik layer7-protocol
- PAT是如何工作的
- PAT 乙级题:1002. 写出这个数 (20)
- PAT (Advanced Level) Practise 1001-1010
- 数据结构学习与实验指导(一)
- PAT Basic Level 1001-1010解题报告
- 1001. 害死人不偿命的(3n+1)猜想
- 1002. 写出这个数
- 1032. 挖掘机技术哪家强
- 1001. 害死人不偿命的(3n+1)猜想 (PAT basic)
- 1002. 写出这个数(PAT Basic)
- 1004. 成绩排名(PAT Basic)
- 1006. 换个格式输出整数(PAT Basic)
- 1007. 素数对猜想(PAT Basic)
- 1008. 数组元素循环右移问题
- 1009. 说反话(PAT Basic)
- 1011. A+B和C(PAT Basic)