2617 Happy 2009

2617 Happy 2009
 1 #include < stdio.h >
 2 #include < string .h >
 3 int  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}

你可能感兴趣的:(2617 Happy 2009)