1093 count PAT's
2015-11-06 21:04
375 查看
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
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
#include<iostream> #include<string> #include<vector> using namespace std; int main(){ for(string str;cin>>str;){ int all_t = 0; for(int i = 0;i < str.length();i++){ if(str[i] == 'T'){ all_t ++; } } int sum = 0; int count_P = 0; int count_T = 0; for(int i = 0;i < str.length();i++){ if(str[i] == 'P'){ count_P++; }else if(str[i] == 'T'){ count_T++; }else{ sum+=(count_P*(all_t-count_T))%1000000007; sum = sum % 1000000007; } } cout<<sum<<endl; } return 0; }
相关文章推荐
- 操作系统的历史 History of OS part 1
- 红黑树的插入C实现
- 栈的顺序
- 【小松教你手游开发】【unity实用技能】unity 内存调试方法
- 边界值
- Codeforces Round #192 (Div. 1) A. Purification(贪心模拟+清除每行每列)
- 1083 List Grades
- Android Event.getX 与getRawX的区别
- 局域网 其它主机ping不通win7, 解决
- Attribute在.net编程中的应用(六)
- 1012 the Best Rank
- 冒泡排序 文法推导
- C#总结项目《影院售票系统》编写总结完结篇
- android82 启动Actvity和Activity的生命周期
- 【FastDev4Android框架开发】重写WebView网页加载以及JavaScript注入详解(二十三)
- 从哈密尔顿路径谈NP问题
- IOS网络请求图片失败原因及解决办法
- hdu 1686 Oulipo /poj 3461
- 我的第一个Activity遇到的问题
- 1006 Sign in and Sign out