PAT 甲级 1093. Count PAT's (25)

来源:互联网 发布:logitech g502 mac 编辑:程序博客网 时间:2024/05/19 17: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:
APPAPT
Sample Output:
2
#include <algorithm>#include <queue>#include <cstring>#include <iostream>#include <vector>#include <string>using namespace std;int main() {string s;cin >> s;int len = s.length(), result = 0, cntp = 0, cntt = 0;for (int i = 0; i < len; i++) {if (s[i] == 'T')cntt++;}for (int i = 0; i < len; i++) {if (s[i] == 'P') cntp++;if (s[i] == 'T') cntt--;if (s[i] == 'A') result = (result + (cntp*cntt) % 1000000007) % 1000000007;}cout << result << endl;return 0;}


原创粉丝点击