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. 监控系统-nagios

    Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设备,打印机等.在系统或服务状态异常发出邮件或短信报警第一 ...

  2. Django1.11.4中文文档

    Django管理站点¶ 自动管理界面是Django最强大的部分之一.它从您的模型中读取元数据,以提供一个快速,以模型为中心的界面,让受信任的用户可以管理您网站上的内容.管理员建议的使用仅限于组织的内部 ...

  3. kubernetes对象之deployment

    系列目录 简述 Deployment为Pod和ReplicaSet提供了一个声明式定义(declarative)方法,用来替代以前的ReplicationController来方便的管理应用.典型的应 ...

  4. kubernetes故障现场一之Orphaned pod

    系列目录 问题描述:周五写字楼整体停电,周一再来的时候发现很多pod的状态都是Terminating,经排查是因为测试环境kubernetes集群中的有些节点是PC机,停电后需要手动开机才能起来.起来 ...

  5. JQuery日记 5.31 JQuery对象的生成

    JQuery对象的生成 1 selector为不论什么可转换false的空值   返回空JQuery对象 2 selector为字符串   2.1 selector为html字符串或有id属性的标签 ...

  6. mybatis入门(五)

    根据用户名称模糊查询用户信息 @Test public void findUserByNameTest() throws IOException { // 通过工厂得到SqlSession SqlSe ...

  7. Android笔记之为自定义对话框添加移动动画效果

    给底部的对话框添加移动动画效果 可通过Window.setWindowAnimations(int resId)设置 SharingDialog.java package com.bu_ish.sha ...

  8. [数据挖掘课程笔记]关联规则挖掘 - Apriori算法

    两种度量: 支持度(support)  support(A→B) = count(AUB)/N (N是数据库中记录的条数) 自信度(confidence)confidence(A→B) = count ...

  9. AndroidDragAndDrop.java

    以下代码使用ApiDemos-debug.apk进行测试 package com.saucelabs.appium; import io.appium.java_client.AppiumDriver ...

  10. win7 64位系统与Ubuntu14.04 64位系统双系统安装【转】

    本文转载自:http://blog.csdn.net/strugglepeach/article/details/51260886 Window 7 + Ubuntu 双系统安装   硬件: Thin ...