Strings of Power
来源:互联网 发布:阿里云服务器部署项目 编辑:程序博客网 时间:2024/06/05 15:51
Strings of Power
Volodya likes listening to heavy metal and(occasionally) reading. No wonder Volodya is especially interested in textsconcerning his favourite music style.
Volodya calls a string powerful if it startswith "heavy" and ends with "metal". Finding all powerfulsubstrings (by substring Volodya means a subsequence of consecutive charactersin a string) in a given text makes our hero especially joyful. Recently he feltan enormous fit of energy while reading a certain text. So Volodya decided tocount all powerful substrings in this text and brag about it all day long. Helphim in this difficult task. Two substrings are considered different if theyappear at the different positions in the text.
For simplicity, let us assume that Volodya'stext can be represented as a single string.
Input
Input contains a single non-empty stringconsisting of the lowercase Latin alphabet letters. Length of this string willnot be greater than 1e6 characters.
Output
Print exactly one number — thenumber 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 certainlypowerful.
In the second sample the string"heavymetalismetal" contains two powerful substrings:"heavymetal" and "heavymetalismetal".
分析:
此题的意思就是输入的一句话中有多少个从heavy开头到metal结束的句子。
主要就是用string数组来放句子。
代码:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{ char s[1000000];
while(cin>>s)
{
int length=strlen(s);
int x=0,y=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')
{
x++;
}
if(s[i]=='m'&&s[i+1]=='e'&&s[i+2]=='t'&&s[i+3]=='a'&&s[i+4]=='l')
{
y+=x;
}
}
cout<<y<<endl;
}
return 0;
}
- B. Strings of Power
- Strings of Power
- [选拔赛]Strings of Power
- Strings of Power
- Strings of Power
- B. Strings of Power
- Strings of Power
- codeforces Strings of Power
- Strings of Power
- cf 318B. Strings of Power
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- Power Strings
- 四元数2
- Firebug入门指南
- 【读书笔记】CDC-设计中的逻辑思维
- iframe和父级页之间的通信
- 【项目那些事儿】项目常总结2013.7.6
- Strings of Power
- 在Excel2003中按颜色进行排序
- 谷歌浏览器开发工具使用教程
- pku 1511 Invitation Cards(最短路径)
- 毕业两年总结
- 编程之“与、或(&|)”的使用技巧
- 博客小技巧
- 【读书笔记】linux系统中"共享文件"的原理
- 让Office 2003与Office 2010完美共存