The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 D Carneginon
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 visitoroh, 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 visitorsenior!
. - 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 visitorfriend!
.
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!");
}
}
}
- 微信公众平台开发接口PHP SDK完整版
- 我的HTML总结之HTML发展史
- BZOJ 4152: [AMPPZ2014]The Captain(最短路)
- js获取div编辑框,textarea,input text的光标位置,兼容FF和IE
- BZOJ 4289: PA2012 Tax(最短路)
- php QR Code二维码生成类
- BZOJ 3714: [PA2014]Kuglarz(最小生成树)
- 我的HTML总结之表单
- php 二维码生成类
- HDU 2516 取石子游戏(斐波那契博弈)
- angularjs MVC、模块化、依赖注入详解
- BZOJ 2940: [Poi2000]条纹(Multi-Nim)
- PHP页面跳转代码
- angularjs 控制器、作用域、广播详解
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Win10+Unlocker3+VMware15.5+MacOS10.14+xcode+QT for ios+虚拟机苹果系统 自用 实践笔记
- OpenGL ES 纹理过滤模式-glTexParameteri
- Jenkins时间修改为北京时间
- OpenGL ES for Android 绘制一个点
- OpenGL ES for Android 绘制线
- Jenkins自定义主题
- OpenGL ES for Android 绘制三角形
- Centos7 安装 Tomcat8 的正确姿势 并设置开机自启 实践笔记
- ASP.NET Core 使用 Google 验证码(reCAPTCHA v3)代替传统验证码
- Centos7 安装 Tomcat8 伪集群 的正确姿势 并设置开机自启 实践笔记
- 问题合集,持续更新
- ASP.NET Core Swagger接入使用IdentityServer4 的 WebApi
- 基于IdentityServer4的OIDC实现单点登录(SSO)原理简析
- OpenGL ES 变量、结构体、语句、函数、精度
- OpenGL ES for Android 绘制矩形和正方形