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

 

http://www.patest.cn/contests/pat-a-practise/1093

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

 

这道题是2015考研机试前的那个PAT的D题 http://www.patest.cn/contests/pat-a-101-125-1-2015-03-14 

这道题很简单,所以考试结束后原英文题目放到了A中,中文版的也放到了B中    http://www.cnblogs.com/asinlzm/p/4440603.html

 

 1 #include<stdio.h>
 2 #include<string.h>  
 3 
 4 int main()
 5 {
 6     char str[100000];
 7     gets(str);
 8     
 9     int istr=strlen(str);
10     long long numA=0,numT=0,numP=0;
11     while(istr>0)
12     {
13           istr--;
14           if('T'==str[istr]) numT++;
15           else if('A'==str[istr]) numA+=numT;
16           else numP+=numA;          
17     }
18       
19     printf("%lld",numP%1000000007);
20     return 0;
21     
22 }

 

posted on 2015-04-30 10:08  Asin_LZM  阅读(250)  评论(0编辑  收藏  举报