• PAT甲级——A1093 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 1 characters containing only PA, 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 <iostream>
     2 #include <vector>
     3 #include <string>
     4 using namespace std;
     5 int main()
     6 {
     7     string input;
     8     getline(cin,input);
     9     int Pnum[input.size()]={0};//Pnum数组表示该字符左侧字符P的数量
    10     for(int i=1;i<input.size();++i)
    11     {//如果i-1位置是P字符,则Pnum[i]=Pnum[i-1]+1;否则Pnum[i]=Pnum[i-1]
    12         Pnum[i]=Pnum[i-1];
    13         if(input[i-1]=='P')
    14             ++Pnum[i];
    15     }
    16     int tnum=0,sumPAT=0;//tnum表示该字符右侧字符T的数量,sumPAT表示PAT字符串总数
    17     for(int i=input.size()-1;i>=0;--i)
    18         if(input[i]=='T')
    19             ++tnum;
    20         else if(input[i]=='A')
    21             sumPAT=(sumPAT+Pnum[i]*tnum)%1000000007;
    22     printf("%d
    ",sumPAT);
    23     return 0;
    24 }
     
  • 相关阅读:
    Linux 打包文件 及 备份数据库
    YII事务
    MySQL两种存储引擎: MyISAM和InnoDB 简单总结
    mysql锁表查询和解锁操作
    Yii+MYSQL锁表防止并发情况下重复数据的方法
    B/S和C/S的区别及应用【转】
    Yii2.0的乐观锁与悲观锁
    【事务】脏读、不可重复读、幻读解释
    利用非阻塞的文件排他锁
    自定义实例化class
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11349323.html
Copyright © 2020-2023  润新知