1093 Count PAT's(25 分)
2024-08-29 23:52:10
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 1 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
#include<cstdio>
#include<cstring>
const int maxn = ;
const int MOD = ;
char str[maxn];
int leftNumP[maxn] = {};
int main(){
fgets(str,maxn,stdin);
int len = strlen(str);
for(int i = ; i < len; i++){
if(i > ){
leftNumP[i] = leftNumP[i-];
}
if(str[i] == 'P'){
leftNumP[i]++;
}
}
int ans = ,rightNumT = ;
for(int i = len - ; i >= ; i--){
if(str[i] == 'T'){
rightNumT++;
}else if(str[i] == 'A'){
ans = (ans + rightNumT * leftNumP[i]) % MOD;
}
}
printf("%d\n",ans);
return ;
}
最新文章
- 【Web动画】SVG 实现复杂线条动画
- 我的.NET自学之路
- Linux下搭建DNS服务器
- Spring(四)Bean注入方试
- CSS3实现10种Loading效果
- Visual Studio 2015 与GitLab 团队项目与管理【2】
- jqgrid 中设置列不排序
- openwrt 更改 debug 等级(hostapd)
- JAVA基础——Arrays工具类十大常用方法
- CvIntHaarClassifier
- 谷歌内核浏览器 iframe内容的 tab切换 滚动条消失
- MFC下用sdl 显示bmp、rgb、yuv
- [ExtJS5学习笔记]第七节 Extjs5的组件components及其模板事件方法学习
- .net文件上传默认限制了大小4M
- python 线程/线程锁/信号量
- javap浅析-书籍第3章的手写稿样稿
- git clean(转载)
- csu oj 1341 string and arrays
- Meandering Through the Maze of MFC Message and Command Routing MFC消息路由机制分析
- Spring事务异常rollback-only