PAT 1093. Count PAT's
2016-11-09 15:19
288 查看
(1)这里以A为遍历的参考,若遍历到的字符为A,则由这个A组成的PAT的个数就是这个A左边的P的个数乘以这个A右边的T的个数。
(2)string.length() 和 string.size()两者存在区别
时间限制
120 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CAO, Peng
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)string.length() 和 string.size()两者存在区别
1093. Count PAT's (25)
时间限制120 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CAO, Peng
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:
APPAPT
Sample Output:
2
#include <iostream> #include <string> using namespace std; string s; int p[100005], t[100005]; int main() { cin >> s; p[0] = s[0] == 'P' ? 1 : 0; t[0] = s[0] == 'T' ? 1 : 0; // string.length() and string.size() for(int i=1; i<s.size(); i++) { p[i] = p[i-1]; t[i] = t[i-1]; if(s[i] == 'P') p[i]++; if(s[i] == 'T') t[i]++; } long rst = 0; for(int i=1; i<s.size(); i++) if(s[i] == 'A') rst += p[i] * (t[s.size() - 1] - t[i]); cout << rst % 1000000007; return 0; }
相关文章推荐
- 1093. Count PAT's
- 1093. Count PAT's 解析
- 1093.Count PAT's
- 1093 count PAT's
- 1093. Count PAT's (25)
- 1093.Count PAT's (25)...to be continued...
- PAT-A-1093. Count PAT's (25)
- 1093. Count PAT's (25)
- PAT1093: Count PAT's
- PAT A 1093. Count PAT's (25)
- 1093. Count PAT's (25)
- PAT--1093. Count PAT's (25)
- 1093. Count PAT's (25)
- Pat(Advanced Level)Practice--1093(Count PAT's)
- 1093. Count PAT's (25)
- 【PAT】1093. Count PAT's (25)
- PAT 1093. Count PAT's (25)
- 【PAT】【Advanced Level】1093. Count PAT's (25)
- 1093. Count PAT's
- 1093. Count PAT's (25)【计数】——PAT (Advanced Level) Practise