1093. Count PAT's (25)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 105characters 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
 1 #include<string>
 2 #include<iostream>
 3 #include<map>
 4 
 5 using namespace std;
 6 
 7 int numofP[100001];
 8 int numofPA[100001];
 9 int main()
10 {
11     string str;
12     getline(cin,str);
13     int P,A,T;
14     T = 0;
15     int sumofP = 0;
16     for(int i = 0 ; i < str.length() ;++i)
17     {
18         if(str[i] == P)
19             ++sumofP;
20         numofP[i] = sumofP;
21     }
22 
23     int sumofPA = 0;
24     for(int i = 0 ; i < str.length() ;++i)
25     {
26         if(str[i] == A)
27         {
28             sumofPA += numofP[i];
29         }
30         numofPA[i] = sumofPA;
31     }
32 
33     int sumofPAT = 0;
34     for(int i = 0 ; i < str.length() ;++i)
35     {
36         if(str[i] == T)
37         {
38             sumofPAT += numofPA[i];
39             sumofPAT = sumofPAT % 1000000007;//坑点
40         }
41     }
42     cout << sumofPAT <<endl;
43     return 0;
44 }

 

以上是关于1093. Count PAT's (25)的主要内容,如果未能解决你的问题,请参考以下文章

1093. Count PAT's (25)计数——PAT (Advanced Level) Practise

1093. Count PAT's (25)

PAT Advanced 1093 Count PAT's (25分)

PAT (Advanced Level) 1093. Count PAT's (25)

A1093 Count PAT's (25 分)

1093 Count PAT's