zoukankan      html  css  js  c++  java
  • PAT Advanced 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 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

    计数方法,先计数T的个数,再遍历P增加,T减少,遇到一个A进行累加

    #include <iostream>
    using namespace std;
    int main()
    {
        string s;
        getline(cin,s);
        long long P=0,A=0,T=0,sum=0;
        for(int i=0;i<s.length();i++)
            if(s[i]=='T') T++;
        for(int i=0;i<s.length();i++){
            if(s[i]=='P') P++;
            if(s[i]=='T') T--;
            if(s[i]=='A') sum+=((P%1000000007*T%1000000007)%1000000007);
        }
        cout<<sum%1000000007;
        system("pause");
        return 0;
    }
  • 相关阅读:
    实验17:NAT
    实验16:ACL
    实验15: STP
    实验14:VLAN间的路由
    实验13:VLAN/TRUNK/VTP/
    Linux软件管理--RPM工具
    Linux拓展练习部分--输入输出 / find部分 /基础拓展2
    linux文件管理--压缩打包
    find 文件查找
    防火墙知识点
  • 原文地址:https://www.cnblogs.com/littlepage/p/12216152.html
Copyright © 2011-2022 走看看