PAT 1093. Count PAT's (25)
来源:互联网 发布:红蜘蛛多媒体软件 编辑:程序博客网 时间:2024/05/19 19:59
1093. Count PAT's (25)
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
这道题有个坑,一开始以为最后算出结果取余就可以了,然后最后两个case过不了。后来发现是计算过程中就要取余。。不然可能会溢出。。代码如下:
#include <iostream>#include <string>using namespace std;int main(void){string raw;int p=0,pa=0,pat=0;cin>>raw;for(int i=0;i<raw.size();i++){if(raw[i]=='P')p++;else if(raw[i]=='A')pa+=p;elsepat+=pa;pat%=1000000007;}cout<<pat;}
- 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)
- C++ 标准库和标准模板库
- iOS开发系列—内存管理
- C语言之循环链表
- 最适合程序员编程的10款字体
- jQuery的简单了解
- PAT 1093. Count PAT's (25)
- ARP协议和RARP协议详解及ARP瓜攻击
- HDU 2460 Network(Tarjan求解桥+LCA)
- 线程池总结
- Android系统在超级终端下必会的命令大全(adb shell命令大全)
- OpenCV_基于混合高斯模型GMM的运动目标检测
- C语言之双向链表之操作
- 131 Palindrome Partitioning
- VC++6.0中设置注释多行代码的快捷键组合