zoukankan      html  css  js  c++  java
  • Strings of Power

    B. Strings of Power

    Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.

    Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of consecutive characters in a string) in a given text makes our hero especially joyful. Recently he felt an enormous fit of energy while reading a certain text. So Volodya decided to count all powerful substrings in this text and brag about it all day long. Help him in this difficult task. Two substrings are considered different if they appear at the different positions in the text.

    For simplicity, let us assume that Volodya's text can be represented as a single string.

    Input

    Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 1e6 characters.

    Output

    Print exactly one number — the number of powerful substrings of the given string.

    Sample test(s)

    input

    heavymetalisheavymetal

    heavymetalismetal

    trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou

    output

    3

    2

    3

    Note

    In the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful.

    In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal".

    继续水,不解释,贴代码;

    #include<iostream>
    #include<string.h>
    #include<stdio.h>
    using namespace std;
    char s[2000000];
    int main()
    {
        while(scanf("%s",s)!=EOF)
        {
            int length=strlen(s);
            long long a=0,b=0;
            for(int i=0;i<length;i++)
            {
                if(s[i]=='h'&&s[i+1]=='e'&&s[i+2]=='a'&&s[i+3]=='v'&&s[i+4]=='y')
                {
                    i+=4;
                    a++;
                }
                if(s[i]=='m'&&s[i+1]=='e'&&s[i+2]=='t'&&s[i+3]=='a'&&s[i+4]=='l')
                {
                    i+=4;
                    b+=a;
                }
            }
            printf("%d
    ",b);
        }
        return 0;
    }
    


  • 相关阅读:
    在OpenEuler中安装轻量化调试工具CGDB
    nginx服务器 server location映射路径配置
    hadoop HDFS文件系统角色及文件读写流程
    Linux系统Tomcat服务自启动脚本
    Linux系统软件安装的三种方式
    linux基础命令
    Java多线程解析
    多线程的典型应用场景---多个生产者多个消费者对共享资源的处理
    10.16变量的作用域和生存周期
    10.15sizeof用法
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3178027.html
Copyright © 2011-2022 走看看