杭电3617Happy 2009

Happy 2009

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2727    Accepted Submission(s): 914


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. 
 

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 happy happ acm y hahappyppy
 

Sample Output
  
  
2 1 2
 

Author
yifenfei
 

Source
 

Recommend
yifenfei   |   We have carefully selected several similar problems for you:   2608  2637  1421  2634  2822 
 




直接算就行了,算法时间复杂度为n;

附ac代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int h,a,p,i,m,n,j,k,l,y,help;
char s[110000];
int main()
{
	while(gets(s))
	{
		l=strlen(s);
		h=a=p=y=help=0;
		for(i=0;i<l;i++)
		{
			if(s[i]=='h')
			h++;
			if(s[i]=='a')
			{
				if(a<h)
				{
					a++;
					help+=2;
				}
			}
			if(s[i]=='p')
			{
				if(p<help)
				p++;
			}
			if(s[i]=='y')
			{
				if(y<p/2)
				y++;
			}
		}
		printf("%d\n",y);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值