CodeForces Good Words

Good Words
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
 

Description

standard input/output
Statements

Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a is 'good' if it has a substring which is equal tob. However, a is 'almost good' if by inserting a single letter inside of it, it would become 'good'. For example, if a = 'start' and b = 'tear':b is not found inside of a, so it is not 'good', but if we inserted the letter 'e' inside of a, it will become 'good' ('steart'), so a is 'almost good' in this case. Your task is to determine whether the word a is 'good' or 'almost good' or neither.

Input

The input consists of several test cases. The first line of the input contains a single integer T, the number of the test cases. Each of the following T lines represents a test case and contains two space separated strings a and b, each of them consists of lower case English letters. It is guaranteed that the length of a is between 4 and 1000, and the length of b is exactly 4.

Output

For each test case, you should output one line: if a is 'good' print 'good', if a is 'almost good' print 'almost good', otherwise print 'none'.

Sample Input

Input
4
smart mark
start tear
abracadabra crab
testyourcode your
Output
almost good
almost good
none
good

Hint

A substring of string s is another string t that occurs in s. Let's say we have a string s = "abcdefg" Possible valid substrings:"a","b","d","g","cde","abcdefg". Possible invalid substrings: "k","ac","bcef","dh".

尝试一下新的风格

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

typedef long long LL;

char a[1005];
char b[10];

int main()
{
    //freopen("input.txt","r",stdin);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>a;
        cin>>b;
        int len=strlen(a);
        int flag=0;
        int cas,cou;
        for(int i=0;i<len-3;i++)
        {
            if(a[i]==b[0]){
                if(a[i+1]==b[1]&&a[i+2]==b[2]&&a[i+3]==b[3])   {flag=1;break;}
            }
        }
        if(flag){
            cout<<"good"<<endl;
            continue;
        }
        for(int i=0;i<len;i++)
        {
                if(a[i]==b[0]&&a[i+1]==b[1]&&a[i+2]==b[2])   {flag=1;break;}
                if(a[i]==b[0]&&a[i+1]==b[1]&&a[i+2]==b[3])   {flag=1;break;}
                if(a[i]==b[0]&&a[i+1]==b[2]&&a[i+2]==b[3])   {flag=1;break;}
                if(a[i]==b[1]&&a[i+1]==b[2]&&a[i+2]==b[3])   {flag=1;break;}
        }
        if(flag)   {cout<<"almost good"<<endl;}
        else  {cout<<"none"<<endl;}
    }
}

  

原文地址:https://www.cnblogs.com/Hyouka/p/5719718.html