【字符串水题】HDU2617Happy 2009
来源:互联网 发布:canon mp230 清零软件 编辑:程序博客网 时间:2024/06/05 01:55
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2617
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
看到我加粗放大的那句话没有,注意了,不要改变字母的位置!!所以我们需要加上判断,WA给跪了一次
代码:
#include<iostream>#include<cstdio>#include<string>#include<cstring>using namespace std;int main(){ string str; while(getline(cin,str)){ int h=0,a=0,p=0,y=0; for(int i=0;i<str.size();i++){ switch (str[i]){ case 'h':h++;break; case 'a':if(h>a)a++;break; // 加判断是为了保证不改变字母的位置; case 'p':if(p<2*a)p++;break; case 'y':if(p/2>y)y++;break; default :break; } } int t=min(min(h,a),min(y,p/2)); cout<<t<<endl; } return 0;}
0 0
- 【字符串水题】HDU2617Happy 2009
- 字符串水题
- poj1936~~字符串水题
- ZOJ1099字符串水题
- 字符串水题_CJ
- 字符串”水“题
- hdu 1048 字符串水题
- hdu 1062字符串水题
- 字符串水题 N - ?(>_o)!
- uva1339(字符串水题)
- POJ 3080 字符串水题
- hdu 5773 字符串水题
- 古代密码 字符串水题
- UVA10018 字符串处理水题
- Vowel Counting hdu3079 字符串水题
- POJ2039--To and Fro--字符串水题
- uva 10252 - Common Permutation 字符串水题
- HDU 1228 A + B 字符串水题
- HDU_2604Queuing
- POJ 2752 Seek the Name, Seek the Fame
- HDU 2068:RPG的错排【排列组合】
- nginx配置ssl加密(单/双向认证、部分https)
- Red Hat 7.0 配置使用CentOS 7.0 Yum 源
- 【字符串水题】HDU2617Happy 2009
- 利用github page搭建博客
- Linux下Caffe初学测试笔记
- Android 中MD5算法生成字符串
- 第二周项目4:穷举法解决组合问题(3)
- hdu 1358 Period
- HDU 3074 带权并查集
- Swift Any和AnyObject类型
- C++ static静态成员变量和静态成员函数