Good Morning
Time Limit: 1000 ms Memory Limit: 65536 kB Solved: 242 Tried: 2806
Description
Sam loves Lily very much that he shows his love to her through all kinds of ways. This morning, Lily received an e-mail from Sam. Lily knows that Sam hided "good morning" in this mail. Lily tried several ways to resort the letters (including the space ' ') so that more "good morning"s could be found. The number of "good morning" appeared in a specified string equals the number of positions from which Lily could see a consecutive string "good morning".
With so many letters, Lily is about to be dizzy. She asks you to tell her what is the maximum number of "good morning"s appear in this mail after rearranged in some way.
Input
First an integer T (T <= 20), indicates there are T test cases.
Every test case begins with a single line consist of only lowercase letters and space which is at most 1000 characters.
Output
For every test case, you should output "Case #k: " first, where k indicates the case number and starts at 1. Then output an integer indicating the answer to this test case.
Sample Input
2
gninrom doog
ggoooodd mmoorrnniinngg
Sample Output
Case #1: 1
Case #2: 2
Source
Sichuan State Programming Contest 2011
看题的时候一定要认真地去读题,千万不能略读。
题意:读入一个字符串,重组字符之后,输出字符串中good morning的个数
特殊样例:
请理解下面的case
1
ggoooodd(空格)(空格)mmoorrnniinng
这个case要输出2
原因是上面的字母可以重组为
good morningood morning
这样就出现了两个good morning
code:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<string> 5 #include<algorithm> 6 using namespace std; 7 8 int main() 9 { 10 int t,i; 11 int cas=0; 12 string str; 13 int num[10]; 14 cin>>t; 15 getline(cin,str); 16 while(t--) 17 { 18 memset(num,0,sizeof(num)); 19 getline(cin,str); 20 for(i=0;i<str.length();i++) 21 { 22 if(str[i]=='g') 23 num[0]++; 24 else if(str[i]=='o') 25 num[1]++; 26 else if(str[i]=='d') 27 num[2]++; 28 else if(str[i]=='m') 29 num[3]++; 30 else if(str[i]=='n') 31 num[4]++; 32 else if(str[i]=='r') 33 num[5]++; 34 else if(str[i]=='i') 35 num[6]++; 36 else if(str[i]==' ') 37 num[7]++; 38 } 39 if(num[0]>0) 40 num[0]--; 41 num[1]/=3; 42 num[4]/=2; 43 int count=*min_element(num,num+7); 44 cout<<"Case #"<<++cas<<": "<<count<<endl; 45 } 46 return 0; 47 }