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 ...
随机推荐
- Fighting regressions with git bisect---within git bisect algorithm
https://www.kernel.org/pub/software/scm/git/docs/git-bisect-lk2009.html Fighting regressions with gi ...
- AngularJS 实现 双击排序
关键代码:html <th class="col-md-3"><a href="" ng-click="desc('2',la=!l ...
- python--函数嵌套 命名空间
函数的嵌套调用 def func(): print(123) def func2(): func() print(345) func2() #结果:123 345 函数的嵌套定义 def func() ...
- MVC3-表单
[.NET Core已取消]Html.BeginForm() 该方法用于构建一个From表单的开始,他的构造方法为:Html.BeginForm("ActionName", &qu ...
- 为什么在 Java 中用 (low+high)>>>1 代替 (low+high)/2 或 (low+high)>>1 来计算平均值呢?好在哪里?
>>>与>>是位运算符,只对整型有效(不能用于浮点型).当是整型的时候(low+high)>>1可以代替(low+high)/2.>>>是无 ...
- linux中vi编辑器(转载)
三种模式相互切换 在命令终端输入vi进入vi编辑器. 命令模式:进入编辑器即进入命令模式, 输入模式:在命令模式下输入“i ”进入输入模式: 末行模式:按“:”进入末行模式: 在输入模式切换至末行模式 ...
- 【推荐】初级.NET程序员,你必须知道的EF知识和经验
阅读目录 推荐MiniProfiler插件 数据准备 foreach循环的陷进 AutoMapper工具 联表查询统计 性能提升之AsNonUnicode 性能提升之AsNoTracking 多字 ...
- GCJ Qualification Round 2016 B题
经典的翻饼问题,直接做:从下往上看,已翻好的饼忽略掉:从上往下,连续的已翻好的一起翻过来:整个翻过来. /* * Author : ben */ #include <cstdio> #in ...
- 网络直播流媒体协议的选择讨论,RTSP,RTMP,HTTP,私有协议?
最近有不少人在EasyDarwin的交流群里面问关于花椒.映客手机直播技术的问题,还有RTSP.RTMP协议选择的问题,这里个人谈一下自己的愚见. 1.不管是RTSP/RTP.RTMP.HTTP,亦或 ...
- dataware fact 事实 不可更新 data warehousing business intelligence 优劣判据
不可 Kimball维度建模 维度建模,而非数据建模 文本型度量是对某些事情的描述.虽然以文本方式度量事实是可行的,但是应将其放入维度表中,除非对事实表的每个行,其文本是唯一的. 数据仓库的好坏直接取 ...