加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

PAT_A1093#Count PAT's

发布时间:2020-12-15 07:57:44 所属栏目:Java 来源:网络整理
导读:Source: PAT A1093?Count PAT‘s?(25?分) Description: 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,and the 6th characters.

Source:

PAT A1093?Count PAT‘s?(25?分)

Description:

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,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,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

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("%lldn",p);
24 
25     return 0;
26 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读