PAT_A1093#Count PAT's
Source:
Description:
The string
APPAPT
contains twoPAT
'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 1 characters containing only
P
,A
, orT
.
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
Keys:
- 模拟题
Code:
1 #include <cstdio> 2 #include <string> 3 #include <iostream> 4 using namespace std; 5 const int MOD = 1000000007; 6 7 int main() 8 { 9 #ifdef ONLINE_JUDGE 10 #else 11 freopen("test.txt", "r", stdin); 12 #endif 13 14 string s; 15 cin >> s; 16 long long t=0, p=0, a=0; 17 for(int i=s.size()-1; i>=0; i--) 18 { 19 if(s[i]=='P') p = (p+a)%MOD; 20 else if(s[i]=='A') a = (a+t)%MOD; 21 else t = (t+1)%MOD; 22 } 23 printf("%lld\n", p); 24 25 return 0; 26 }