Good Morning

F - Good Morning
Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu

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 \leq 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


gninrom doog 
ggoooodd mmoorrnniinngg

Sample Output

Case #1: 1 
Case #2: 2



#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int t,i;
	int cas=0;
	string str;
	int num[10];
	cin>>t;
	getline(cin,str);
	while(t--)
	{
		memset(num,0,sizeof(num));
		getline(cin,str);
		for(i=0;i<str.length();i++)
		{
			if(str[i]=='g')num[0]++;
			else if(str[i]=='o')num[1]++;
			else if(str[i]=='d')num[2]++;
			else if(str[i]=='m')num[3]++;
			else if(str[i]=='n')num[4]++;
			else if(str[i]=='r')num[5]++;
			else if(str[i]=='i')num[6]++;
			else if(str[i]==' ')num[7]++;
		}
		if(num[0]>0) num[0]--;num[1]/=3;num[4]/=2;
		int count=*min_element(num,num+7) ;
		cout<<"Case #"<<++cas<<": "<<count<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值