A13106 | Shuffle Hashing
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $p$ , consisting of lowercase Latin letters, and shuffle the letters randomly in it to obtain $p'$ ( $p'$ can still be equal to $p$ );
2. generate two random strings, consisting of lowercase Latin letters, $s_1$ and $s_2$ (any of these strings can be empty);
3. the resulting hash $h = s_1 + p' + s_2$ , 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.
Polycarp decided to store the hash of the password, generated by the following algorithm:
1. 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$ );
2. generate two random strings, consisting of lowercase Latin letters, $s_1$ and $s_2$ (any of these strings can be empty);
3. the resulting hash $h = s_1 + p' + s_2$ , 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 \le t \le 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$ .
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 $s_1$ and $s_2$ 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 $s_1=$ "n", $s_2$ 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.
In the second test case both $s_1$ and $s_2$ 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 $s_1=$ "n", $s_2$ 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted