pat 1093. Count PAT's (25)
2015-11-29 16:30
549 查看
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:
Sample Output:
2
只要数每一个A前面的P和T的个数,然后相乘,再所有的A的P*T的数相加即可。#include<iostream>
using namespace std;
#include<string.h>
#include<algorithm>
#define maxn 0x7fffffff
char 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;
}
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 0x7fffffff
char 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;
}
相关文章推荐
- Notification方法更新
- Python中内置数据结构的方法总结
- Notification方法更新
- 深入理解JavaBean内省
- 面试时应该如何进行自我介绍呢
- 在Linux或mac上配置github提交代码到github仓库
- Ubuntu vim配置文件及系统安装
- java/HashSet
- codeforces Educational Codeforces Round 2 A. Extract Numbers
- Ubuntu vim配置文件及系统安装
- Java使用局部变量的一些要点
- Freemarker自定义分页工具类
- Content Provider之MIME类型
- 第三届开源操作系统年度技术年会 --- 资料下载
- PetaPoco dynamic
- Content Provider之MIME类型
- Partition Array
- 短信验证码
- Android之Context、this
- HDU-计算机学院大学生程序设计竞赛(2015’11)1002 投币洗衣机(模拟)