HDU 2617 Happy 2009 (String)

Source: Internet
Author: User

Happy 2009Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2394 Accepted Submission (s): 802


Problem Descriptionno matter you know me or not. Bless Happy in 2009.
Inputthe input contains multiple test cases.
Each test case included one string. There is made up of ' a '-' Z ' or blank. The length of string would not be large than 10000.

Outputfor Each test case tell me how many times "happy" can be constructed by using the string. Forbid to the position of the characters in the string. The answer would small than 1000.
Sample Input
Hopppayppy Happyhapp ACM Yhahappyppy

Sample Output
212


Very simple string, mainly simple practice, 1 a.


#include <iostream> #include <string> #include <map>using namespace std;map<string,int> SMP; int ans;void init () {smp["h"] = 0;smp["ha"] = 0;smp["Hap"] = 0;smp["Happ"] = 0;ans = 0;} inline bool Yes (char c) {if (c = = ' A ' | | c = = ' H ' | | c = = ' P ' | | c = = ' Y ') return true;return false; inline void Add (char c) {if (c = = ' h ') {++smp["H"];} else if (c = = ' A ' && smp["H"]>0) {--smp["h"];++smp["Ha"];} else if (c = = ' P ') {if (smp["Hap"] > 0) {--smp["Hap"];++smp["Happ"];} else if (smp["Ha"] > 0) {--smp["ha"];++smp["Hap"];}} else if (c = = ' Y ' && smp["Happ"] > 0) {++ans;--smp["Happ"];}} void solve (string str) {int len = str.length (); for (int i = 0; i < len; ++i) {if (yes (Str[i])) {Add (Str[i]);}} int main () {string str;while (getline (CIN, str)) {init (); solve (str); cout << ans << endl;} return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.