• 1093. 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 105characters 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
     1 #include<string>
     2 #include<iostream>
     3 #include<map>
     4 
     5 using namespace std;
     6 
     7 int numofP[100001];
     8 int numofPA[100001];
     9 int main()
    10 {
    11     string str;
    12     getline(cin,str);
    13     int P,A,T;
    14     T = 0;
    15     int sumofP = 0;
    16     for(int i = 0 ; i < str.length() ;++i)
    17     {
    18         if(str[i] == 'P')
    19             ++sumofP;
    20         numofP[i] = sumofP;
    21     }
    22 
    23     int sumofPA = 0;
    24     for(int i = 0 ; i < str.length() ;++i)
    25     {
    26         if(str[i] == 'A')
    27         {
    28             sumofPA += numofP[i];
    29         }
    30         numofPA[i] = sumofPA;
    31     }
    32 
    33     int sumofPAT = 0;
    34     for(int i = 0 ; i < str.length() ;++i)
    35     {
    36         if(str[i] == 'T')
    37         {
    38             sumofPAT += numofPA[i];
    39             sumofPAT = sumofPAT % 1000000007;//坑点
    40         }
    41     }
    42     cout << sumofPAT <<endl;
    43     return 0;
    44 }
  • 相关阅读:
    linux 、windows、mac、dns刷新
    Nginx日志切割及其各种服务日志随便切
    https是如何防劫持的
    梁启超-少年中国说
    mongodb-4.2-隋唐笔迹
    connection closed by foreign host
    磁盘类型查看
    魅力男神之解说
    jenkins 更新脚本之expect交互
    nginx 之特殊端口转目录访问
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/5210939.html
Copyright © 2020-2023  润新知