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\n",b);
}
return 0;
}

Strings of Power的更多相关文章

  1. Codeforces Round #188 (Div. 2) B. Strings of Power 水题

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  2. cf Strings of Power

    http://codeforces.com/contest/318/problem/B #include <cstdio> #include <cstring> #includ ...

  3. XSS attack

    <html> <form action="" method="post"> <input type="text" ...

  4. Codeforces Round #188 (Div. 2) C. Perfect Pair 数学

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  5. Codeforces Round #188 (Div. 1 + Div. 2)

    A. Even Odds 奇数个数\(\lfloor \frac{n+1}{2}\rfloor\) B. Strings of Power 从位置0开始,统计heavy个数,若当前为metal,则可以 ...

  6. POJ 2406 Power Strings (KMP)

    Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...

  7. POJ 2406 Power Strings

    F - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  8. poj 2406:Power Strings(KMP算法,next[]数组的理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30069   Accepted: 12553 D ...

  9. POJ 2406:Power Strings

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 41252   Accepted: 17152 D ...

随机推荐

  1. Linux教程 - 管道和重定向

      管道和重定向! 保持数据流动 介绍   在前两节中,我们看了一些可以为我们操作数据的过滤器.在本节中,我们将看到我们如何将它们结合在一起来执行更强大的数据操作. 本节涉及一些阅读.即使这些机制及其 ...

  2. 【MPI】并行奇偶交换排序

    typedef long long __int64; #include "mpi.h" #include <cstdio> #include <algorithm ...

  3. java的多线程之四(线程的操作)

    本文来自:高爽|Coder,原文地址:http://blog.csdn.net/ghsau/article/details/17560467,转载请注明. 线程中断    线程中断涉及到三个方法,如下 ...

  4. 【BZOJ】4720: [Noip2016]换教室

    4720: [Noip2016]换教室 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1690  Solved: 979[Submit][Status ...

  5. bzoj 2466 异或方程组

    对于每个灯,我们用一个变量表示其决策,xu=0表示不选,xu=1表示选.因为每个灯最后必须都亮,所以每个等都对应一个异或方程. 解这个异或方程组,有几种情况: 1.存在唯一解(得到的上三角系数矩阵的主 ...

  6. BZOJ 4197 NOI 2015 寿司晚宴 状压DP

    4197: [Noi2015]寿司晚宴 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 694  Solved: 440[Submit][Status] ...

  7. linux基础环境部署

    Content 0.序 1.更新安装库 2.安装基础库 0.序 本文主要是记录php在 Centos下的安装配置 .文中如无特别说明.表示php-5.6.31代码目录. 1.更新安装库 $ yum u ...

  8. iOS 视频组件

    公司最近要在项目里新增一个随手拍的功能,所以呢我在网上找了个比较不错的demo,顺便研究了下它的代码结构.感谢大神的分享,如有侵权,请告知哦!

  9. 获取不到offsetHeight问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. [Linux] Ubuntu 18 LTS netplan 网络配置

    Ubuntu 18 LTS netplan 网络配置 今天装完 Ubuntu 18 LTS,配置网络时发现Ubuntu 18LTS ifupdown has been replaced by netp ...