HDU 2617 Happy 2009(字符串)
来源:互联网 发布:霍建华林心如形婚 知乎 编辑:程序博客网 时间:2024/06/06 04:18
Happy 2009
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2394 Accepted Submission(s): 802
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.
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 happyhapp acm yhahappyppy
Sample Output
212
很简单的字符串,主要是简单练下手,1A。
#include <iostream>#include <string>#include <map>using namespace std;map<string,int> smp;int ans;void init(){smp["h"] = 0;smp["ha"] = 0;smp["hap"] = 0;smp["happ"] = 0;ans = 0;}inline bool yes(char c){if (c == 'a' || c == 'h' || c == 'p' || c == 'y')return true;return false;}inline void add(char c){if (c == 'h'){++smp["h"];}else if (c == 'a' && smp["h"]>0){--smp["h"];++smp["ha"];}else if (c == 'p'){if (smp["hap"] > 0){--smp["hap"];++smp["happ"];}else if (smp["ha"] > 0){--smp["ha"];++smp["hap"];}}else if (c == 'y' && smp["happ"] > 0){++ans;--smp["happ"];}}void solve(string str){int len = str.length();for (int i = 0; i < len; ++i){if (yes(str[i])){add(str[i]);}}}int main(){string str;while (getline(cin, str)){init();solve(str);cout << ans << endl;}return 0;}
4 0
- HDU 2617 Happy 2009(字符串)
- HDU-2617 Happy 2009 字符串
- hdu 2617 Happy 2009
- hdu 2617 Happy 2009
- HDU 2617 Happy 2009
- hdu_2617 Happy 2009 (字符串)
- HDU 6196 happy happy happy(卡时剪枝)
- HDU 6196 happy happy happy(暴搜+剪枝+dp)
- hdu 6196 happy happy happy
- hdu 3040 Happy Girls(模拟)
- hdu 1452 Happy 2004(快速幂取模)
- HDU 4931 Happy Three Friends(水)
- HDU 5119 Happy Matt Friends(DP)
- hdu 5119 Happy Matt Friends(dp)
- HDU - 5119 Happy Matt Friends(DP)
- HDU 5119 Happy Matt Friends(dp)
- HDU 5119 Happy Matt Friends(DP)
- HDU 5119 Happy Matt Friends(dp)
- windows系统下CMAKE编译QJSON
- logmnr 的使用
- HTML5 Canvas知识点学习笔记
- ruby metaprogramming 03
- Java中ArrayList类的用法
- HDU 2617 Happy 2009(字符串)
- 用VC进行COM编程所必须掌握的理论知识
- OD OC 门
- RadioButton 相应
- 基于Linux平台下的僵尸网络病毒《比尔盖茨》
- PHP 工作原理
- POJ 1088 - 滑雪(动态规划)
- OCP 1Z0 052 44
- 深入浅出 - Android系统移植与平台开发(七)- Android系统的启动