PAT 1093. Count PAT's (25)

题目地址: http://www.patest.cn/contests/pat-a-practise/1093

水题

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 
 5 using namespace std;
 6 
 7 const int MAXN = 100000 + 5;
 8 const int MOD = 1000000007;
 9 int d[MAXN][3];
10 
11 char str[MAXN];
12 
13 int solve(char *s) {
14         int ans = 0;
15         memset(d, 0, sizeof(d));
16         int len = strlen(s);
17         if (s[0] == 'P') ++d[0][0];
18         for (int i = 1; i < len; ++i) {
19                 d[i][0] = d[i - 1][0];
20                 d[i][1] = d[i - 1][1];
21                 if (s[i] == 'P') {
22                         ++d[i][0];
23                 } else if (s[i] == 'A') {
24                         d[i][1] += d[i][0];
25                 } else if (s[i] == 'T') {
26                         d[i][2] += d[i][1];
27                         ans += d[i][2];
28                         ans %= MOD;
29                 }
30         }
31         return ans;
32 }
33         
34 int main() {
35         while(cin >> str) {
36                 cout << solve(str) << endl;
37         }
38         return 0;
39 }

 

posted @ 2015-04-13 10:06  ACSeed  Views(209)  Comments(0)    收藏  举报