Happy 2009

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3276    Accepted Submission(s): 1072

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
 

对于此题,我们先对目标字符串“happy”分析,发现要想组成“happy”,当前字母可不可取是首要问题。

当h的个数小于a时,a是可取的;

同理,当a的个数小于p的一半时,p是可取的;

当p的一半小于y时,y是可取的。

最后所有符合条件的可取的y的个数就是“happy”的个数。

注意:

同一组数据中可能会存在空格,不要忽略了空格的读取。

本文提供gets()和getline()两种读取整行的方法。

AC代码:

 #include<bits/stdc++.h>
using namespace std; char s[]; int main(){
while(gets(s)){
int len=strlen(s);
int h=,a=,p=,y=;
for(int i=;i<len;i++){
if(s[i]=='h')
h++;
else if(s[i]=='a'&&a<h)
a++;
else if(s[i]=='p'&&p/<a)
p++;
else if(s[i]=='y'&&y<(p/))
y++;
}
cout<<y<<endl;
}
return ;
}
 #include<bits/stdc++.h>
using namespace std; string s; int main(){
while(getline(cin,s)){
int len=s.size();
int h=,a=,p=,y=;
for(int i=;i<len;i++){
if(s[i]=='h')
h++;
else if(s[i]=='a'&&a<h)
a++;
else if(s[i]=='p'&&p/<a)
p++;
else if(s[i]=='y'&&y<(p/))
y++;
}
cout<<y<<endl;
}
return ;
}
 

HDU-2617的更多相关文章

  1. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  10. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. WeX5开发指南

    WeX5入门.UI2开发.App开发.服务端开发.扩展资料学习. 1 新手入门 1.1 运行WeX5的demo(视频) 1.2 App开发.调试.打包部署完整过程(视频) 1.3 创建第一个应用(视频 ...

  2. php实现双色球算法

    function DoubleBall(){ $sysBlueball = mt_rand(1,16); $sysRedball = array(1,2,3,4,5,6,7,8,9,10,11,12, ...

  3. [LeetCode]Insert Interval 考虑多种情况

    写太复杂了. 思想:确定带插入区间的每一个边界位于给定区间中的哪个位置,共同拥有5种情况 -1 |(0)_1_(2)|  (3) 当中.0,1,2这三种情况是一样的. 确定每一个带插入区间的两个边界分 ...

  4. oracle [union.minus.intersect]

    union 两张表的相同字段的数据[记录类型和列数要一致],合并,并且去重 can replace with "in" (但是如果是两个不同的表而且没什么关联的话必须要union了 ...

  5. mysql_num_rows

    mysql记录总条数 $sql3 = "select * from inviter where tuijianren = '$session' "; $res3 = mysql_q ...

  6. ubuntu安装rpm格式文件方法(转载)

    red hat 系统用rpm格式的文件安装软件   Debian系列用deb格式的文件安装软件 ubuntu安装软件是用deb格式的文件安装,ubuntu对于rpm格式的文件安装软件是: 先将rmp格 ...

  7. SDWebImage学习

    SDWebImage学习 SDWebImage版本是:'4.2.2' SDWebImage是iOS开发中常用的图片加载的库,能下载并缓存图片.这次就着重介绍SDWebImage的特色功能:下载与缓存. ...

  8. HDU 5296 Annoying problem LCA+树状数组

    题解链接 Annoying problem Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  9. C# 打开指定的目录 记住路径中 / 与 \ 的使用方法

    老生常谈的问题了,C#在指定目录时,路径中要使用 \\.直接看实例 using System; namespace OpenFile{ class OpenFile{ static void Main ...

  10. 3932: [CQOI2015]任务查询系统

    3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 2559  Solved: 819[Submit][Sta ...