zoukankan      html  css  js  c++  java
  • 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 }
     
  • 相关阅读:
    跨页传值另一种方法
    运行nodejs的blog程序遇见问题
    nodejs和mongodb实践
    mongodb数据库实践笔记
    两次分页显示内容——先少后多显示
    Java进阶4表达式中的陷阱
    Java进阶3. 内存回收机制
    Java进阶1. Synchronized 关键字
    Java复习9网路编程
    Java复习8.多线程
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11349323.html
Copyright © 2011-2022 走看看