2019--徐州网络赛D题

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_iS
i

). 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∣≤10
5
, 1 \leq |S| \leq 10^51≤∣S∣≤10
5
, 1 \leq q \leq 10001≤q≤1000
It is guaranteed that q \times (|S|+|T|) \leq 10^7q×(∣S∣+∣T∣)≤10
7
.

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!

用string类写

#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
  string s;
  string x;
  cin>>s;
  int n,q;
  scanf("%d",&q);
  while(q--)
  {
    cin>>x;
    if(s.size()>x.size())
    {
      string::size_type idx=s.find(x);
      if(idx!=string::npos) puts("my child!");
      else puts("oh, child!");
    }
    else if(s.size()<x.size())
    {
      string::size_type idx=x.find(s);
      if(idx!=string::npos) puts("my teacher!");
      else puts("senior!");
    }
    else if(s.size()==x.size())
    {
      if(x!=s) puts("friend!");
      else puts("jntm!");
    }
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值