CF1278A.Shuffle Hashing

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems.

Polycarp decided to store the hash of the password, generated by the following algorithm:

  1. take the password pp, consisting of lowercase Latin letters, and shuffle the letters randomly in it to obtain p′p' (p′p' can still be equal to pp);
  2. generate two random strings, consisting of lowercase Latin letters, s1s_1 and s2s_2 (any of these strings can be empty);
  3. the resulting hash h=s1+p′+s2h = s_1 + p' + s_2, where addition is string concatenation.

For example, let the password p=p = "abacaba". Then p′p' can be equal to "aabcaab". Random strings s1=s1 = "zyx" and s2=s2 = "kjh". Then h=h = "zyxaabcaabkjh".

Note that no letters could be deleted or added to pp to obtain p′p', only the order could be changed.

Now Polycarp asks you to help him to implement the password check module. Given the password pp and the hash hh, check that hh can be the hash for the password pp.

Your program should answer tt independent test cases.

Polycarp 开发了自己的网络服务。作为一个现代化的网络服务,它包含了登录功能,而登录功能必然涉及密码安全问题。

Polycarp 决定存储密码的哈希值,该哈希值通过以下算法生成:

  1. 取由小写拉丁字母组成的密码 pp,将其字母随机打乱得到 p′p'(p′p' 有可能与 pp 相同);
  2. 随机生成两个仅由小写拉丁字母组成的字符串 s1s_1 和 s2s_2(这两个字符串均可为空);
  3. 最终得到的哈希值为 h=s1+p′+s2h = s_1 + p' + s_2,其中 “+” 表示字符串拼接。

例如,设密码 p=p = "abacaba",则 p′p' 可以是 "aabcaab";随机字符串 s1=s_1 = "zyx",s2=s_2 = "kjh",那么 h=h = "zyxaabcaabkjh"。

注意:为得到 p′p',不能从 pp 中删除或添加任何字母,只能改变字母的顺序。

现在 Polycarp 请求你帮助他实现密码校验模块:给定密码 pp 和哈希值 hh,判断 hh 是否可能是密码 pp 对应的哈希值。

你的程序需要处理 tt 个相互独立的测试用例。

输入格式

The first line contains one integer tt (1≤t≤1001 \le t \le 100) — the number of test cases.

The first line of each test case contains a non-empty string pp, consisting of lowercase Latin letters. The length of pp does not exceed 100100.

The second line of each test case contains a non-empty string hh, consisting of lowercase Latin letters. The length of hh does not exceed 100100.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 表示测试用例的数量。

每个测试用例的第一行包含一个非空字符串 pp,由小写拉丁字母组成。pp 的长度不超过 100100。

每个测试用例的第二行包含一个非空字符串 hh,由小写拉丁字母组成。hh 的长度不超过 100100。

输出格式

For each test case print the answer to it — "YES" if the given hash hh could be obtained from the given password pp or "NO" otherwise.

对于每个测试用例,输出对应的答案——如果给定的哈希值 hh 可能由给定的密码 pp 生成,则输出 "YES";否则输出 "NO"。

输入输出样例

  • 输入#1

    5
    abacaba
    zyxaabcaabkjh
    onetwothree
    threetwoone
    one
    zzonneyy
    one
    none
    twenty
    ten

    输出#1

    YES
    YES
    NO
    YES
    NO

说明/提示

The first test case is explained in the statement.

In the second test case both s1s_1 and s2s_2 are empty and p′=p'= "threetwoone" is pp shuffled.

In the third test case the hash could not be obtained from the password.

In the fourth test case s1=s_1= "n", s2s_2 is empty and p′=p'= "one" is pp shuffled (even thought it stayed the same).

In the fifth test case the hash could not be obtained from the password.

第一个测试用例在题目描述中已作解释。

第二个测试用例中,s1s_1 和 s2s_2 均为空,且 p′=p'= "threetwoone" 是 pp 的一个打乱排列。

第三个测试用例中,该哈希值无法由密码得到。

第四个测试用例中,s1=s_1= "n",s2s_2 为空,且 p′=p'= "one" 是 pp 的一个打乱排列(即使它本身未发生变化)。

第五个测试用例中,该哈希值无法由密码得到。

输入解题思路,AI测评打分。不知道怎么写?

首页