happy 2009
Happy 2009
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1242 Accepted Submission(s): 429
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.
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> #include <stdlib.h> int main( ) { int i, j, N, len, h, a, p, y; char str[11000]; while(gets(str) ) { len = strlen(str); i = 0; h = a = p = y = 0; while(str[i]) { if (str[i] == 'h') h++; else if ( str[i] == 'a' && h > a) a++; else if ( str[i] == 'p' && a > p /2) p++; else if ( str[i] == 'y' && p/2 > y ) y++; i++; } printf("%d\n",y); } return 0; }
posted on 2011-09-01 14:34 more think, more gains 阅读(175) 评论(0) 编辑 收藏 举报