Happy 2009
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2439 Accepted Submission(s): 819
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
此题我竟然没做出来,想想我都想哭,我水平怎么这么水。。。。
#include<stdio.h>
#include<string.h>
int main()
{
char string[10012];
int k,i,j;
//getchar();
while(gets(string)!=NULL)
{
int a,b,c1,c2,d;
a=0;b=0;c1=0;c2=0;d=0;
k=strlen(string);
for(i=0;i<k;i++)
{
if(string[i]=='h')
a++;
else if(string[i]=='a'&&a>0)
{ a--; b++; }
else if(string[i]=='p')
{
if(c1>0)
{ c1--; c2++; }
else if(b>0)
{ b--; c1++; }
}
else if(string[i]=='y'&&c2>0)
{ c2--; d++; }
}
printf("%d\n",d);
}
return 0;
} 用的别人的思路。。。 比较好理解