博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu (2617) Happy 2009
阅读量:4463 次
发布时间:2019-06-08

本文共 2150 字,大约阅读时间需要 7 分钟。

Problem Description
No matter you know me or not. Bless you happy in 2009.
 

 

Input
The input contains multiple test cases.
Each test case included one string. There are made up of ‘a’-‘z’ or blank. The length of string will not large than 10000.
 

 

Output
For each test case tell me how many times “happy” can be constructed by using the string. Forbid to change the position of the characters in the string. The answer will small than 1000.
 

 

Sample Input
hopppayppy happy
happ acm y
hahappyppy
 

 

Sample Output
2
1
2
 

 

Author
yifenfei
 
 
Problem analysis:
The problem want  us  count the number of  "happy"  in a string.Of couse, "happy" may not a word, eg: "hoa plpy", in the string it includes one "happy";
But you should notice one case:
For example:  in the string "hy ppappa",it includes zero "happy",because it need a sequence of "h-a-p-p-y"; and the problem is mainly to solve this case;
At first,I have no ideas about this problem,and I have never solved this kind of problems before;
So here I post the code,and this represents a solution to some problems;
And the ideas come from others bolg;
View Code
1 #include
2 #include
3 using namespace std; 4 int main() 5 { 6 char str[10055]; 7 while(gets(str)) 8 { 9 int i;10 int h,a,p1,p2,y;11 h=a=p1=p2=y=0;12 for(i=0;str[i]!='\0';i++)13 {14 if(str[i]=='h')15 h++;16 else if(str[i]=='a')17 {18 if(h>0)19 {20 h--;a++;21 }22 }23 else if(str[i]=='p')24 {25 if(p1>0)26 {27 p1--;p2++;28 }29 else if(a>0)30 {31 a--;p1++;32 }33 }34 else if(str[i]=='y')35 {36 if(p2>0)37 {38 p2--;y++;39 }40 }41 42 }cout<
<

 

 
 

转载于:https://www.cnblogs.com/heat-man/articles/2764235.html

你可能感兴趣的文章
js 不固定传参
查看>>
远程调试UWP遇到新错误Could not generate the root folder for app package ......
查看>>
[倍增][最短路-Floyd][dp]
查看>>
SpringAOP用到了什么代理,以及动态代理与静态代理的区别
查看>>
利用STM32CubeMX来生成USB_HID_Mouse工程【添加ADC】(1)
查看>>
【leetcode】Populating Next Right Pointers in Each Node
查看>>
获取请求参数乱码的问题
查看>>
代码实现:判断E盘目录下是否有后缀名为.jpg的文件,如果有,就输出该文件名称...
查看>>
Android客户端测试点
查看>>
Jquery:怎样让子窗体的div显示在父窗体之上
查看>>
01概率
查看>>
Shell脚本
查看>>
MatLab Load cv::Mat 导入数据
查看>>
html+css相关笔记(一)
查看>>
基于块流协议保证音频优先发送
查看>>
关于互联网的一些数据
查看>>
数据预处理:独热编码(One-Hot Encoding)
查看>>
python将对象名的字符串类型,转化为相应对象的操作方法
查看>>
【NLP新闻-2013.06.03】New Book Where Humans Meet Machines
查看>>
mongodb安装4.0(rpm)
查看>>