Carneginon was a chic bard. But when he was young, he was frivolous and had joined many gangs. Recently, Caneginon was to be crowned, because the king was shocked by his poems and decided to award him the gold medal lecturer. Therefore, Most of people in the Kingdom came to visit him.

However, as a medal lectirer, Carneginon must treat the visitors kindly, including elders and younger generations. In order to maintain order, every visitor received a license with a magic field engraved on it. And the magic field on the licence was made up of lowercase letters.

Carneginon had a unique licence, which could judge whether others are his older or younger. Now, we assume that the sequence on Carneginon's licence is TT and the sequence on visitors' licence is SS. For each visitor,

  • If the length of TT is longer than the length of SS, it's obviously that the visitor is younger. And if SS is a substring of TT, Carneginon would call the visitor my child!. Otherwise, Carneginon would call the visitor oh, child!.

  • If the length of TT is less than the length of SS, it's obviously that the visitor is elder. And if TT is a substring of SS, Carneginon would call the visitor my teacher!. Otherwise, Carneginon would call the visitor senior!.

  • Of course, if the length of TT is equal to the length of SS, the visitor is Carneginon's peer. And if TT is equal to SS, it shows that the visitor entered through an improper way and Carneginon would shout jntm!. Otherwise, Carneginon would call the visitor friend!.

Now, you know the TT (Carneginon's licence), qq (the number of visitors) and each visitor's licence(S_iSi​). Can you judge what Caneginon needs to say when he sees every visitor?

Input

The first line is a string TT, representing Carneginon's license.

The second line is and integer qq, which means the number of visitors.

Then mm lines, for each line, there is a string SS, denoting the visitor's license.

1 \leq |T| \leq 10^51≤∣T∣≤105, 1 \leq |S| \leq 10^51≤∣S∣≤105, 1 \leq q \leq 10001≤q≤1000

It is guaranteed that q \times (|S|+|T|) \leq 10^7q×(∣S∣+∣T∣)≤107.

Output

There are qq lines.

For each SS, output what Carneginon should say correctly.

样例输入复制

abcde
6
abcde
aaaaa
abcd
aaaa
abcdef
abccdefg

样例输出复制

jntm!
friend!
my child!
oh, child!
my teacher!
senior!

这个题简单KMP匹配,直接套模板,就ok,一A;

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<queue>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<cstdio>
#include<cstring>
#define Swap(a,b) a^=b^=a^=b
#define cini(n) scanf("%d",&n)
#define cinl(n) scanf("%lld",&n)
#define cinc(n) scanf("%c",&n)
#define cins(s) scanf("%s",s)
#define coui(n) printf("%d",n)
#define couc(n) printf("%c",n)
#define coul(n) printf("%lld",n)
#define speed ios_base::sync_with_stdio(0)
#define Max(a,b) a>b?a:b
#define Min(a,b) a<b?a:b
#define mem(n,x) memset(n,x,sizeof(n))
#define INF 0x3f3f3f3f
#define maxn 100010
#define esp 1e-9
#define mp(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
//-----------------------*******----------------------------//
int nextt[100005];
void Getnextt(string &p,int nextt[])
{
int pLen = p.size();
nextt[0] = -1;
int k = -1;
int j = 0;
while (j < pLen - 1)
{
//p[k]表示前缀,p[j]表示后缀
if (k == -1 || p[j] == p[k])
{
++k;
++j;
nextt[j] = k;
}
else
{
k = nextt[k];
}
}
}
bool KmpSearch(string &s, string &p)
{
int i = 0;
int j = 0;
int sLen = s.size();
int pLen = p.size();
while (i < sLen && j < pLen)
{
//①如果j = -1,或者当前字符匹配成功(即S[i] == P[j]),都令i++,j++
if (j == -1 || s[i] == p[j])
{
i++;
j++;
}
else
{
//②如果j != -1,且当前字符匹配失败(即S[i] != P[j]),则令 i 不变,j = nextt[j]
//nextt[j]即为j所对应的nextt值
j = nextt[j];
}
}
if (j == pLen)
return true;
else
return false;
}
int main()
{
string s,w;
int n;
cin>>s>>n;
int len=s.size();
while(n--)
{ memset(nextt,0,sizeof(nextt));
cin>>w;
int x=w.size();
// cout<<x<<' '<<len<<endl;
if(x==len)
{
// cout<<-1<<endl;
if(w==s) puts("jntm!");
else puts("friend!");
}
else if(x<len)
{ Getnextt(w,nextt);
if(KmpSearch(s, w)) //w s
puts("my child!");
else
puts("oh, child!");
}
else
{
Getnextt(s,nextt);
if(KmpSearch(w, s))
puts("my teacher!");
else puts("senior!");
}
}
}

The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 D Carneginon的更多相关文章

  1. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 K题 center

    You are given a point set with nn points on the 2D-plane, your task is to find the smallest number o ...

  2. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team

    XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...

  3. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 C Buy Watermelon

    The hot summer came so quickly that Xiaoming and Xiaohong decided to buy a big and sweet watermelon. ...

  4. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 B so easy

    题目链接:https://nanti.jisuanke.com/t/41384 这题暴力能过,我用的是并查集的思想,这个题的数据是为暴力设置的,所以暴力挺快的,但是当他转移的点多了之后,我觉得还是我这 ...

  5. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 A Who is better?

    A After Asgard was destroyed, tanker brought his soldiers to earth, and at the same time took on the ...

  6. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

  7. The Preliminary Contest for ICPC Asia Xuzhou 2019 E XKC's basketball team [单调栈上二分]

    也许更好的阅读体验 \(\mathcal{Description}\) 给n个数,与一个数m,求\(a_i\)右边最后一个至少比\(a_i\)大\(m\)的数与这个数之间有多少个数 \(2\leq n ...

  8. The Preliminary Contest for ICPC Asia Xuzhou 2019

    A:Who is better? 题目链接:https://nanti.jisuanke.com/t/41383 题意: 类似于有N个石子,先手第一次不能拿完,每次后手只能拿 1 到 前一次拿的数量* ...

  9. The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team

    题目链接:https://nanti.jisuanke.com/t/41387 思路:我们需要从后往前维护一个递增的序列. 因为:我们要的是wi + m <= wj,j要取最大,即离i最远的那个 ...

随机推荐

  1. rest_framework-序列化-1

    序列化 定义模型类 from django.db import models # Create your models here. class StuModel(models.Model): SEX_ ...

  2. Centos 7 系统定时重启

    crontab -e         //系统命令 00 08 * * * root systemctl restart docker00 08 * * * root reboot //写入需要重启的 ...

  3. C语言 文件操作(三)

    1.fputs() int fputs(const char *s, FILE *stream); s 代表要输出的字符串的首地址,可以是字符数组名或字符指针变量名. stream 表示向何种流中输出 ...

  4. 从零开始实现放置游戏(十三)——实现战斗挂机(4)添加websocket组件

    前两张,我们已经实现了登陆界面和游戏的主界面.不过游戏主界面的数据都是在前端写死的文本,本章我们给game模块添加websocket组件,实现前后端通信,这样,前端的数据就可以从后端动态获取到了. 一 ...

  5. 一、VMware Workstation 15中文破解版 下载与安装(附密钥)

    下载地址: 下载地址VMware Workstation Pro 15.5.0 Build 14665864https://download3.vmware.com/software/wkst/fil ...

  6. python3(四)list tuple

    # !/usr/bin/env python3 # -*- coding: utf-8 -*- # list是一种有序的集合,可以随时添加和删除其中的元素. classmates = ['Michae ...

  7. 《深入理解 Java 虚拟机》读书笔记:晚期(运行期)优化

    正文 在部分商用虚拟机(Sun HotSpot.IBM J9)中,Java 程序最初是通过解释器进行解释执行的,当虚拟机发现某个方法或代码块的运行特别频繁时,就会把这些代码认定为"热点代码& ...

  8. PyCharm 项目打开窗口设置为当前还是新开一个怎么办?

     前言:       我找这个设置找了好久,后来在一篇博文中才找到,现在记录下来一下,顺便带图解释一下   设置步骤: File -> Setting -> Appearance & ...

  9. 第二章:shell变量

    查看所有全局和局部变量:delare和set 查看所有全局变量:env 定义环境变量: 用户变量在家目录下的~/.bash_profile和~/.bashrc中设置 全局变量在/etc/profile ...

  10. EOS基础全家桶(八)jungle测试网的使用

    简介 前面我们已经学习了一些EOS的基础知识了,但是在EOS主网上的很多操作(比如:抵押.赎回.买卖内存)都是需要EOS链被正式激活后才可使用,而激活EOS链还需要很多的准备操作,我打算在单独的一篇文 ...