| How many happy are there in numbers? |
| Difficulty level: B; run time limit: 1000ms; operating space limit: 51200KB; code length limit: 2000000B |
| Question Description |
|
Tutu is a good student who has a strong mind and ability to observe. Recently he was learning English words, the practice of writing unconsciously wrote a string of lowercase English letters, he found that the string contains a lot of happy, he decided to calculate how many of the happy. The rule is this: when the string extracts arbitrary characters into a new word string, does not change its relative order in the original string, you write a program help graph to figure out how many happy the new word string. |
| Input |
| The input has only one row and contains a string. The string is made up of lowercase letters a–z. This string length does not exceed 10000. |
| Output |
| A non-complex integer. Indicates that the number of words happy can be composed up to the rules described in the topic. |
| Input example |
| Hahappyppy |
| Output example |
| 2 |
Puzzle: Data good water look I hack them! I think I have a very good writing ... (Fog
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;TenInlineintRead () { One intx=0, sig=1;CharCh=GetChar (); A while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} - while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); - returnx*=Sig; the } -InlinevoidWriteintx) { - if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; - intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; + for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } + CharChintcnt[4]; A voidinit () { at for(Ch=getchar (); isalpha (CH); ch=GetChar ()) { - if(ch=='h') cnt[0]++; - if(ch=='a')if(cnt[1]<cnt[0]) cnt[1]++; - if(ch=='P')if(cnt[2]< (cnt[1]<<1)) cnt[2]++; - if(ch=='y')if(cnt[3]< (cnt[2]>>1)) cnt[3]++; - } in } - voidWork () { to return; + } - voidprint () { theWrite (cnt[3]); * return; $ }Panax Notoginseng intMain () {init (); work ();p rint ();return 0;}
The original Stupid code:
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn=10000+Ten; One ints[4][maxn],tot[4],cnt[4]; A intCheckintDintt) { - for(; cnt[d]<tot[d];cnt[d]++){ - if(s[d][cnt[d]]>t)returnS[d][cnt[d]]; the}return-1; - } -InlineintRead () { - intx=0, sig=1;CharCh=GetChar (); + while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} - while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); + returnx*=Sig; A } atInlinevoidWriteintx) { - if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; - intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; - for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } - Charch; in voidinit () { - intt=0; to for(Ch=getchar (); isalpha (CH); ch=GetChar ()) { + if(ch=='h') s[0][tot[0]++]=t++; - Else if(ch=='a') s[1][tot[1]++]=t++; the Else if(ch=='P') s[2][tot[2]++]=t++; * Elses[3][tot[3]++]=t++; $ }Panax Notoginseng return; - } the intans; + voidWork () { A for(intI=0; i<tot[0];i++){ the intt=s[0][i]; + if((T=check (1, T)) <0) Break; - if((T=check (2, T)) <0) Break; $ if((T=check (2, T)) <0) Break; $ if((T=check (3, T)) <0) Break; -ans++; - } the return; - }Wuyi voidprint () { the write (ans); - return; Wu } - intMain () {init (); work ();p rint ();return 0;}
Coj 0036 Number Happy How many are there?