CF1278A.Shuffle Hashing
普及/提高-
通过率:0%
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:
- take the password p , consisting of lowercase Latin letters, and shuffle the letters randomly in it to obtain p′ ( p′ can still be equal to p );
- generate two random strings, consisting of lowercase Latin letters, s1 and s2 (any of these strings can be empty);
- the resulting hash h=s1+p′+s2 , where addition is string concatenation.
For example, let the password p= "abacaba". Then p′ can be equal to "aabcaab". Random strings s1= "zyx" and s2= "kjh". Then h= "zyxaabcaabkjh".
Note that no letters could be deleted or added to p to obtain p′ , only the order could be changed.
Now Polycarp asks you to help him to implement the password check module. Given the password p and the hash h , check that h can be the hash for the password p .
Your program should answer t independent test cases.
输入格式
The first line contains one integer t ( 1≤t≤100 ) — the number of test cases.
The first line of each test case contains a non-empty string p , consisting of lowercase Latin letters. The length of p does not exceed 100 .
The second line of each test case contains a non-empty string h , consisting of lowercase Latin letters. The length of h does not exceed 100 .
输出格式
For each test case print the answer to it — "YES" if the given hash h could be obtained from the given password p or "NO" otherwise.
输入输出样例
输入#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 s1 and s2 are empty and p′= "threetwoone" is p shuffled.
In the third test case the hash could not be obtained from the password.
In the fourth test case s1= "n", s2 is empty and p′= "one" is p shuffled (even thought it stayed the same).
In the fifth test case the hash could not be obtained from the password.