zoukankan      html  css  js  c++  java
  • 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 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 <cstdlib>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <string.h>
     5 #include <vector>
     6 #include <set>
     7 using namespace std;
     8 
     9 int main(int argc, char *argv[])
    10 {
    11     
    12     char s[100010];
    13     gets(s);
    14 long long count=0;
    15     int len=strlen(s);
    16     if(len==0)
    17     {
    18         printf("0");
    19         system("PAUSE");
    20         return 0;
    21      }  
    22     int countt=0; 
    23      for(int i=0;i<len;i++)
    24     {
    25     if(s[i]=='T')countt++;
    26     } 
    27 int countp=0;
    28     for(int i=0;i<len;i++)
    29 {
    30 if(s[i]=='P')countp++;
    31 if(s[i]=='A')count+=countp*countt;
    32 if(s[i]=='T')countt--;
    33 }
    34      printf("%lld",count%1000000007);
    35     system("PAUSE");
    36    
    37     
    38     return EXIT_SUCCESS;
    39 }
  • 相关阅读:
    Educational Codeforces Round 49 (Rated for Div. 2)
    Codeforces Round #506 (Div. 3)
    multiset
    C++中substr函数的用法
    7.30 背包问题
    7.29 dp动态规划
    7.27 图论 存图 前向星 最短路 dijstra算法 SPFA算法
    7.26 搜索进阶(状压搜索,迭代加深搜索)
    7.23 深搜广搜
    7.24 二分搜索
  • 原文地址:https://www.cnblogs.com/ligen/p/4338425.html
Copyright © 2011-2022 走看看