zoukankan      html  css  js  c++  java
  • hdu 3617 Happy 2009

    Happy 2009

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


    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
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #define MAX 11000
    using namespace std;
    int main()
    {
    	int n,m,j,i;
    	char s[MAX];
    	while(gets(s))
    	{
    		int len=strlen(s);
    		int h,a,p,y;
    		h=a=p=y=0;
    		for(i=0;i<len;i++)
    		{
    			if(s[i]=='h')
    			    h++;
    			if(s[i]=='a')
    			{
    				if(a<h)
    				a++;
    			}
    			if(s[i]=='p')
    			{
    				if(p<2*a)
    				p++;
    			}
    			if(s[i]=='y')
    			{
    				if(y<p/2)
    				y++;
    			}
    		}
    		printf("%d
    ",y);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    python05-循环
    python03-列表
    python03 input
    python02-灭霸的选择
    python学习小记01--萌新的进化
    Linux—-软件安装
    linux-认识与分析日志
    Esxi遇到问题汇总。
    xx
    Pramp mock interview (4th practice): Matrix Spiral Print
  • 原文地址:https://www.cnblogs.com/tonghao/p/4989806.html
Copyright © 2011-2022 走看看