pat 1093. Count PAT's (25)
来源:互联网 发布:给淘宝差评怎么写 编辑:程序博客网 时间:2024/05/28 19:23
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
只要数每一个A前面的P和T的个数,然后相乘,再所有的A的P*T的数相加即可。
#include<iostream>using namespace std;#include<string.h>#include<algorithm>#define maxn 0x7fffffffchar s[100005];int a[100005]; int main() { int i,j,s1=0,s2,k,s3=0; cin>>s; for(j=0,i=0;s[i]!=0;i++) if(s[i]=='A') a[j++]=i; int f=0,k1,k2; s2=0; for(k2=a[0]+1;k2<strlen(s);k2++) if(s[k2]=='T') s2++; for(i=0;i<j;i++) { for(k1=f;k1<a[i];k1++) if(s[k1]=='P') s1++; f=a[i]+1; if(i>0) { for(k2=a[i-1]+1;k2<a[i];k2++) if(s[k2]=='T') s2--; } s3=(s3+s1*s2)%1000000007; } cout<<s3<<endl; return 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)
- Maven的安装及配置
- 短信--Text与PDU
- 信号量、互斥锁,读写锁和条件变量的区别
- 设置自己喜欢的eclipse背景风格
- Git 基础
- pat 1093. Count PAT's (25)
- 欢迎使用CSDN-markdown编辑器
- Educational Codeforces Round 2B. Queries about less or equal elements(二分查找)
- Android开发Service
- iOS MKMapView 地图视图
- HDU-计算机学院大学生程序设计竞赛(2015’11)1002 投币洗衣机(模拟)
- 我看Java虚拟机(4)---Javac编译器
- 短信验证码
- Java 8中处理日期和时间