HDU-2617
Happy 2009
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3276 Accepted Submission(s): 1072Problem DescriptionNo matter you know me or not. Bless you happy in 2009.InputThe 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.OutputFor 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 Inputhopppayppy happyhapp acm yhahappyppySample Output212
对于此题,我们先对目标字符串“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的更多相关文章
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- 小贝_mysql主从复制作用以及案例
mysql主从复制 简要: 一.mysql用户授权 二.mysql bin-log日志 三.mysql主从复制 一.mysql用户授权 1.命令 2.作用:进行权限控制 3.样例: (备注: 同意 ...
- Sublime Text3 配置设置攻略
转载:http://cloudbbs.org/forum.php?mod=viewthread&tid=3620 sublime本身功能有限,我们需要装上一些插件使其变得强大.sublime在 ...
- iOS移动开发周报-第20期
iOS移动开发周报-第20期iOS移动开发周报-第20期 [摘要]:本期iOS移动开发周报带来如下内容:iOS 通知中心扩展制作入门,iOS APP可执行文件的组成,objc非主流代码技巧等. 教程 ...
- .NET 4.0 WCF WebConfig aspNetCompatibilityEnabled 属性
近来被一个问题困扰了好久,好好的一个WCF后台服务,在发布机器上可用.在自己机器上没法跑起来. 一直提示兼容性问题,后来在网上找来解决方案,但问题依旧.没办法又从客户的服务器上重新把配置内容 拿下来审 ...
- c# SQLServer导入大批量数据
说来惭愧,关于批量导入数据,一直采用的是最原始的方式,一条一条插入,或者100条一块批量插入,这种方式,五十步笑百步,并没有明显的性能提升, 昨天在从别的库查询数据到DataTable内存中,然后插入 ...
- 基于struts2的学生报道管理系统(附github源码地址)
本项目参考了<java web轻量级开发全体验>,加入了对mysql的支持. 一.基本业务功能 通过struts2框架,结合mysql数据库构建一个学生报到管理系统,来模拟学生报到登记的过 ...
- html5 file 上传图片
说明:开发环境 vs2012 mvc4项目,后台语言csharp 1.前端代码 <html xmlns="http://www.w3.org/1999/xhtml"> ...
- JS中正则匹配开头不带空格,结尾也不带空格的字符串
在做项目的时候,要求限制SSID的长度.以及开头和结尾不能是空格. var reg = /^\S.{0,30}\S$/ "$$$ $$".match(reg); ==> ...
- ActiveMQ的消息的(含附件)发送和接收使用
首先介绍一下ActiveMQ的版本:apache-activemq-5.10.2 启动MQ:activemq.bat 下面来编写MQ的发送类: 里面的发送ip和模式名称可以根据具体的实际情况填写. S ...
- ABAP 实现Excel 粘贴复制
"设置需要复制的区域 CLEAR gv_range. gs_ole2-row1 = . gs_ole2-col1 = . gs_ole2-row2 = . gs_ole2-col2 = . ...