pat 1093. Count PAT's (25)
来源:互联网 发布:淘宝助理5.8.7.0 编辑:程序博客网 时间:2024/05/19 17:27
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
代码:
#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>using namespace std;int main(){ string s; cin>>s; int len=s.length(); int *P=new int[len+10]; int *PA=new int[len+10]; int *PAT=new int[len+10]; memset(P,0,sizeof(P)); memset(PA,0,sizeof(PA)); memset(PAT,0,sizeof(PAT)); for(int i=0;i<len;i++) { if(s[i]=='P') { if(i==0) P[i]=1; else P[i]=P[i-1]+1; } else { if(i==0) P[i]=0; else P[i]=P[i-1]; } } for(int i=0;i<len;i++) { if(s[i]=='A'&&P[i]!=0) { if(i==0) PA[i]=1; else { PA[i]=PA[i-1]+P[i]; PA[i]%=1000000007; } } else { if(i==0) PA[i]=0; else PA[i]=PA[i-1]; } } for(int i=0;i<len;i++) { if(s[i]=='T'&&PA[i]!=0) { if(i==0) PAT[i]=1; else { PAT[i]=PAT[i-1]+PA[i]; PAT[i]%=1000000007; } } else { if(i==0) PAT[i]=0; else PAT[i]=PAT[i-1]; } } cout<<PAT[len-1]<<endl;}
0 0
- 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)
- 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)
- 1093. Count PAT's (25)
- 关于虚拟继承和直接继承
- Android底层基础之NDK(一)
- Android开源项目 异步图片缓存库 Universal-Image-Loader
- leetcode 052 —— N-Queens II
- 功能强大的Windows PowerShell
- pat 1093. Count PAT's (25)
- 使用zip4j加密和解密文件和目录
- Android环境搭建
- 2015 Multi-University Training Contest 2 1004 苹果树 dp+单调队列
- HDU 5294 Tricks Device (最短路变体) 2015多校联合第一场
- 关于Comparable的compareTo的正确写法
- bj java 初学 2015-07-23
- 终于决定要写博客啦
- 控制器