Pat(Advanced Level)Practice--1093(Count PAT's)
来源:互联网 发布:消防调试联动编程 编辑:程序博客网 时间:2024/06/15 15:06
Pat1093代码
题目描述:
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<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#define MAXN 100005#define MOD 1000000007using namespace std;int main(int argc,char *argv[]){char str[MAXN];scanf("%s",str);int numT=0;int numAT=0;int numPAT=0;for(int i=strlen(str)-1;i>=0;i--){if(str[i]=='T'){++numT;}else if(str[i]=='A'){//记录AT组合的个数,其中包括之前统计的AT个数,加上这个A与后面全部T组合的个数numAT=(numAT+numT)%MOD;}else{numPAT=(numPAT+numAT)%MOD;}}printf("%d\n",numPAT);return 0;}
0 0
- Pat(Advanced Level)Practice--1093(Count PAT's)
- PAT (Advanced Level) Practise 1093 Count PAT's (25)
- PAT (Advanced Level) Practise 1093 Count PAT's (25)
- 【PAT】【Advanced Level】1093. Count PAT's (25)
- PAT (Advanced Level) Practice 1006
- Pat(Advanced Level)Practice--1025(PAT Ranking)
- Pat(Advanced Level)Practice--1075(PAT Judge)
- Pat(Advanced Level)Practice--1055(The World's Richest)
- Pat(Advanced Level)Practice--1003(Emergency)
- Pat(Advanced Level)Practice--1004(Counting Leaves)
- Pat(Advanced Level)Practice--1008(Elevator)
- Pat(Advanced Level)Practice--1010(Radix)
- Pat(Advanced Level)Practice--1015(Reversible Primes)
- Pat(Advanced Level)Practice--1024(Palindromic Number)
- Pat(Advanced Level)Practice--1028(List Sorting)
- Pat(Advanced Level)Practice--1029(Median)
- Pat(Advanced Level)Practice--1030(Travel Plan)
- Pat(Advanced Level)Practice--1035(Password)
- 24>文件下载
- 并查集总结(一)
- nginx+tomcat实现单IP,多域名,多站点的访问配置教程
- c语言初学错误
- mark一个关于虚拟机的小问题
- Pat(Advanced Level)Practice--1093(Count PAT's)
- Nginx+Tomcat实现单IP、多域名的访问?
- Linux 日志级别(loglevel)详解
- cocos2d 《watchout》笔记
- Hive总结(九)Hive体系结构
- 分治法 归并排序(递归算法)
- MVC模式与三层架构的区别
- UML状态图
- 新兴Web技术杂谈 之 WebSocket