Codeforce 2016 Al-Baath University Training Camp Contest-1

来源:互联网 发布:软件开发阶段包括 编辑:程序博客网 时间:2024/06/17 06:44
F. Good Words
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

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': bis 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'.

Example
input
4smart markstart tearabracadabra crabtestyourcode your
output
almost goodalmost goodnonegood
Note

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".



思路:这题做的时候开始一直wrong answer to test 2,试了很多遍没找着原因,索性直接换套写法,过于简单具体思路见代码;


下面附上WA2代码,路过的大神望指教错在哪。

#include<iostream>#include<vector>#include<string>#include<queue>#include<cmath>#include<cstring>#include<cstdio>#include<algorithm>#define llong long long#define Min(a,b) (a<b?a:b)#define Max(a,b) (a>b?a:b)#define Abs(a) ((a)>0?(a):-(a))#define Mod(a,b) (((a)-1+(b))%(b)+1)using namespace std;#define INF 0x3f3f3f3fint dp[1005][10];char str1[1005],str2[10];int main(){  int t;  scanf("%d",&t);  while(t--)  {    scanf("%s",str1);    scanf("%s",str2);    int len1=strlen(str1);    int sum=0,flag=0,fflag=0,cnt=0;    for(int i=0;i<len1;i++)    {      if(str1[i]==str2[0]||str1[i]==str2[1])      {        sum=1;cnt=0;flag=0;fflag=0;        int tt=0;        if(str1[i]==str2[1]&&str1[i]!=str2[0]) tt=1;        for(int j=1+tt;j<4;j++)        {          if(str1[i+j-cnt]==str2[j])          {            sum++;          }          else          {            cnt++;          }        }        if(sum==4)        {          flag=1;break;        }        if(sum==3)        {          fflag=1;break;        }      }    }    if(flag)    {      printf("good\n");    }    else if(fflag)    {      printf("almost good\n");    }    else printf("none\n");  }}



正确代码:

/**********************orz orz orz orz orz orz**********************/#include<iostream>#include<vector>#include<string>#include<queue>#include<cmath>#include<cstring>#include<cstdio>#include<algorithm>#define llong long long#define Min(a,b) (a<b?a:b)#define Max(a,b) (a>b?a:b)#define Abs(a) ((a)>0?(a):-(a))#define Mod(a,b) (((a)-1+(b))%(b)+1)using namespace std;#define INF 0x3f3f3f3fint main(){  int t;  scanf("%d",&t);  while(t--)  {    string str1,str2,a,b,c,d;    cin>>str1>>str2;    if(str1.find(str2)!=-1)    {      printf("good\n");continue;    }    for(int i=0;i<4;i++)    {      if(i!=0)      a+=str2[i];    }    for(int i=0;i<4;i++)    {      if(i!=1)      b+=str2[i];    }    //cout<<b<<endl;    for(int i=0;i<4;i++)    {      if(i!=2)      c+=str2[i];    }    for(int i=0;i<3;i++)    {      d+=str2[i];    }    if(str1.find(a)!=-1||str1.find(b)!=-1||str1.find(c)!=-1||str1.find(d)!=-1)    {      printf("almost good\n");    }    else printf("none\n");  }}



0 0
原创粉丝点击