[转]PAT甲级练习1093. Count PAT's (25)
来源:互联网 发布:手机淘宝店招尺寸 编辑:程序博客网 时间:2024/06/12 11:04
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:APPAPTSample 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;}
0 0
- [转]PAT甲级练习1093. Count PAT's (25)
- PAT甲级1093. Count PAT's (25)
- PAT 甲级 1093. Count PAT's (25)
- 1093. Count PAT’s (25)-PAT甲级真题
- 1040. 有几个PAT(25)PAT乙级&&1093. Count PAT's (25) PAT甲级
- PAT 1093. Count PAT's (25)
- PAT A 1093. Count PAT's (25)
- pat 1093. Count PAT's (25)
- PAT 1093. Count PAT's (25)
- 【PAT】1093. Count PAT's (25)
- pat 1093. Count PAT's (25)
- PAT 1093. Count PAT's (25)
- PAT 1093. Count PAT's (25)(有意思)
- PAT--1093. Count PAT's (25)
- PAT A 1093. Count PAT's (25)
- PAT-A 1093. Count PAT's (25)
- PAT 1093. Count PAT's (25)
- PAT-A-1093. Count PAT's (25)
- 检测IP地址的正则表达式
- MyEclipse配置中文版javadoc(API)图文教程
- 欢迎使用CSDN-markdown编辑器
- android 图片轮播
- 浅析jQuery整体框架与实现(上)
- [转]PAT甲级练习1093. Count PAT's (25)
- ubuntu下使用 rxtx串口通讯
- J2EE应用性能调优(目录)
- Linux文件查找
- jvm参数设置
- 【视频+工程】最新版unity3d视频教程下载-新手入门系列-20讲
- 深入浅出 RPC
- FrameLayout(帧布局)实现闪烁霓虹灯效果
- mac 配置 mysql