CDOJ 486 Good Morning 傻逼题

Good Morning

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.uestc.edu.cn/#/problem/show/486

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

2
gninrom doog
ggoooodd mmoorrnniinngg

Sample Output

Case #1: 1
Case #2: 2

HINT

 

题意

让你重新排列,使得出现最多的goodmorning

题解:

注意goodmorningoodmorning这个数据,这个数据输出应该是2

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=202501;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//*************************************************************************************

int a[30];
char s[maxn];
int main()
{
    //この戦い终わった、故郷に帰って结婚するだん!!! ??\
    cout<<"please hack me"<<endl;
    int t=read();
    for(int cas=1;cas<=t;cas++)
    {
        memset(a,0,sizeof(a));
        gets(s);
        for(int i=0;i<strlen(s);i++)
        {
            if(s[i]<='z'&&s[i]>='a')
            a[s[i]-'a']++;
        }
        int num=inf;
        num=min(num,a['g'-'a']-1);
        num=min(num,a['o'-'a']/3);
        num=min(num,a['d'-'a']);
        num=min(num,a['m'-'a']);
        num=min(num,a['r'-'a']);
        num=min(num,a['n'-'a']/2);
        num=min(num,a['i'-'a']);
        printf("Case #%d: %d\n",cas,num);
    }
}

 

posted @ 2015-07-26 18:26  qscqesze  阅读(483)  评论(0编辑  收藏  举报