zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    【bzoj1036】【ZJOI2008】树的统计
    AE基础(8)PageLayout属性设置和添加元素
    AE基础(7)布局控件与地图控件关联
    UtilityAction扩展
    UtilityAction
    AE基础(6)数据查询与选择
    NavigationAction
    LayerAction
    AE基础(5)鹰眼功能
    AE基础(4)画几何图形
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/5210939.html
Copyright © 2011-2022 走看看