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 ...
随机推荐
- 教你使用 Reflexil 反编译.NET
简介 反编译的方式有很多种,其实最靠谱的还是IL反编译. 如果不懂IL可以尝试我这边文章入门:http://www.wxzzz.com/278.html 不过我下面要说的不是IL这种底层的代码反编译, ...
- java对象访问
下面这句代码: Object obj = new Object(); 对象引用在栈中,对象实体存在堆中,引用的方式有两种,分别是通过句柄访问对象和通过直接指针访问对象. Sun HotSpot使用第二 ...
- Spring Cloud(十):服务网关zuul(转)
前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个 ...
- Android API Guides---NFC Basics
本文档介绍了Android中运行基本任务NFC. 它说明了怎样在NDEF消息的形式发送和接收数据的NFC并介绍了支持这些功能的Android框架的API. 对于更高级的主题.包含与非NDEF数据工 ...
- 当CSDN携手Markdown
当CSDN携手Markdown Tags: CSDN Markdown 当CSDN携手Markdown Markdown CSDN-Markdown 也不知道是不是基于 Github 崛起的因素,Ma ...
- RYU改动监听port Mininet在custom自建拓扑和连接到指定控制器命令解释
1.RYU控制器改动监听port 在ryu/ryu/ofproto以下的ofproto_common.py watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc ...
- 一个兼容性比较好的图片左右滚动的js
下载地址:http://www.cnblogs.com/RightDear/admin/Files.aspx 文件:shhds.rar
- 九度OJ 1092:Fibonacci (递归)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1923 解决:1378 题目描述: The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} ...
- 从模版生成 uri Golang 的 html/template 包不太适合于这种情况
模板 - Go/Golang 框架 Echo 文档 http://go-echo.org/guide/templates/ Templates | Echo - High performance, m ...
- Android笔记之为TextView设置边框
效果图 text_view_background.xml <?xml version="1.0" encoding="utf-8"?> <sh ...