posts - 20,  comments - 6,  trackbacks - 0
 1#include<stdio.h>
 2#include<string.h>
 3int main()
 4{
 5    char a[10001],b[10001]={0};
 6    int i,j,k,c,l,n,hash[4];
 7    while(gets(a))
 8    {
 9        l=strlen(a);
10        memset(hash,0,sizeof(hash));
11        k=0;
12        j=0;
13        c=0;
14        for(i=0;i<l;i++)
15        {
16            if(a[i]=='h'||a[i]=='a'||a[i]=='p'||a[i]=='y')
17            {
18                b[k]=a[i];
19                k++;
20            }

21        }

22        b[k]='\0';
23        l=strlen(b);
24        k=0;
25        for(i=0;i<l;i++)
26        {
27            if(b[i]=='h')
28            {
29                hash[0]++;
30            }

31            if(b[i]=='a')
32            {
33                if((hash[1]+1)<=hash[0])
34                {
35                    hash[1]++;
36                }

37                    b[i]=' ';
38                
39            }

40            if(b[i]=='p')
41            {
42                if((hash[2]+1)<=2*hash[1])
43                {
44                    hash[2]++;
45                }

46                b[i]=' ';
47                
48            }

49            if(b[i]=='y')
50            {
51                if((hash[3]+1)*2<=hash[2])
52                {
53                    hash[3]++;
54                }

55                    b[i]=' ';
56                
57            }

58        }

59        while(hash[3]&&hash[2]>=2)
60        {
61                c++;
62                hash[0]-=1;
63                hash[1]-=1;
64                hash[2]-=2;
65                hash[3]-=1;
66        }

67            
68
69        printf("%d\n",c);
70    }

71        
72}
posted on 2009-01-27 14:07 混沌的云 阅读(206) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年1月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿(1)

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜