【codeforces】1278A. Shuffle Hashing

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, s1s1 and s2s2 (any of these strings can be empty);
  3. the resulting hash h=s1+p′+s2h=s1+p′+s2, 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.

Input

The first line contains one integer tt (1≤t≤1001≤t≤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.

Output

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.

Example

input
5
abacaba
zyxaabcaabkjh
onetwothree
threetwoone
one
zzonneyy
one
none
twenty
ten
output
YES
YES
NO
YES
NO

Note

The first test case is explained in the statement.

In the second test case both s1s1 and s2s2 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=s1= “n”, s2s2 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.

题解

直接暴力

代码

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
 
char s1[105],s2[105];
 
int main()
{
    int t;
    cin>>t;
    getchar();
    while(t--){
        gets(s1);
        gets(s2);
        int len_1,len_2;
        len_1=strlen(s1);
        len_2=strlen(s2);
        sort(s1,s1+len_1);
        if(len_1>len_2){
            printf("NO\n");
            continue;
        }
        bool flag;
        for(int i=0;i<len_2-len_1+1;i++)
        {
            flag=1;
            char t[105];
            strcpy(t,s2);
            sort(t+i,t+i+len_1);
            for(int j=0;j<len_1;j++){
                if(s1[j]!=t[i+j]){
                    flag=0;
                    break;
                }
            }
            if(flag)
                break;
        }
        if(flag)
			printf("YES\n");
        else
			printf("NO\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值