pat1093 Count PAT's
来源:互联网 发布:餐饮软件考试指定 编辑:程序博客网 时间:2024/06/07 07:03
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 <iostream>#include <vector>using namespace std;int main() {string in;int mode = 1000000007;int p[100010], t[100010];cin >> in;for (int i = 0; i < in.size(); ++i){if(i == 0) p[i] = 0;else p[i] = p[i-1];if(in[i] == 'P') {p[i] += 1;}}for(int i = in.size()-1; i >= 0; i--) {if(i == in.size()-1) {t[i] = 0;} else {t[i] = t[i+1];}if(in[i] == 'T') {t[i] += 1;}}int ans = 0;for (int i = 0; i < in.size(); ++i){if(in[i] == 'A') {ans = ((p[i]*t[i])%mode+ans)%mode;}}cout << ans << endl;return 0;}
0 0
- pat1093 Count PAT's
- 1093.Count PAT's
- 1093. Count PAT's
- 1093. Count PAT's
- 1093 count PAT's
- 1093. Count PAT's
- 1093. Count PAT's
- 1093. Count PAT's
- PAT 1093. Count PAT's
- PAT 1093. Count PAT's
- PAT 1093. Count PAT's
- 【PAT】1093. Count PAT's
- PAT1093
- 1093. Count PAT's (25)
- 1093. Count PAT's (25)
- 1093. Count PAT's (25)
- 1093. Count PAT's (25)
- 1093. Count PAT's (25)
- 浅谈胶片与数码的不同
- AJAX的七宗罪
- iOS 9系统策略更新,微信分享无法使用解决办法
- 在mac中如何用命令行打开webstorm
- oracle 子查询的解决方法~
- pat1093 Count PAT's
- iOS APP打包时的4个选项含义
- 局部变量问题
- Orchard相关名词
- 第八周项目1 - 建立顺序串的算法库
- MySQL 主从备份
- 【串项目1 - 建立顺序串的算法库——第8周】
- Simple way to check if an image bitmap is blur
- ACE_Proactor实现